/**
 * @license
 * Copyright 2010-2024 Three.js Authors
 * SPDX-License-Identifier: MIT
 */
const Ka = "170";
const Tn = "", Xt = "srgb", pi = "srgb-linear", kr = "linear", it = "srgb";
const _s = "300 es";
class Gn {
  addEventListener(e, t) {
    this._listeners === void 0 && (this._listeners = {});
    const r = this._listeners;
    r[e] === void 0 && (r[e] = []), r[e].indexOf(t) === -1 && r[e].push(t);
  }
  hasEventListener(e, t) {
    if (this._listeners === void 0) return !1;
    const r = this._listeners;
    return r[e] !== void 0 && r[e].indexOf(t) !== -1;
  }
  removeEventListener(e, t) {
    if (this._listeners === void 0) return;
    const n = this._listeners[e];
    if (n !== void 0) {
      const i = n.indexOf(t);
      i !== -1 && n.splice(i, 1);
    }
  }
  dispatchEvent(e) {
    if (this._listeners === void 0) return;
    const r = this._listeners[e.type];
    if (r !== void 0) {
      e.target = this;
      const n = r.slice(0);
      for (let i = 0, s = n.length; i < s; i++)
        n[i].call(this, e);
      e.target = null;
    }
  }
}
const Et = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"], na = Math.PI / 180, ka = 180 / Math.PI;
function mi() {
  const a = Math.random() * 4294967295 | 0, e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, r = Math.random() * 4294967295 | 0;
  return (Et[a & 255] + Et[a >> 8 & 255] + Et[a >> 16 & 255] + Et[a >> 24 & 255] + "-" + Et[e & 255] + Et[e >> 8 & 255] + "-" + Et[e >> 16 & 15 | 64] + Et[e >> 24 & 255] + "-" + Et[t & 63 | 128] + Et[t >> 8 & 255] + "-" + Et[t >> 16 & 255] + Et[t >> 24 & 255] + Et[r & 255] + Et[r >> 8 & 255] + Et[r >> 16 & 255] + Et[r >> 24 & 255]).toLowerCase();
}
function bt(a, e, t) {
  return Math.max(e, Math.min(t, a));
}
function Tl(a, e) {
  return (a % e + e) % e;
}
function ia(a, e, t) {
  return (1 - t) * a + t * e;
}
function Ri(a, e) {
  switch (e.constructor) {
    case Float32Array:
      return a;
    case Uint32Array:
      return a / 4294967295;
    case Uint16Array:
      return a / 65535;
    case Uint8Array:
      return a / 255;
    case Int32Array:
      return Math.max(a / 2147483647, -1);
    case Int16Array:
      return Math.max(a / 32767, -1);
    case Int8Array:
      return Math.max(a / 127, -1);
    default:
      throw new Error("Invalid component type.");
  }
}
function It(a, e) {
  switch (e.constructor) {
    case Float32Array:
      return a;
    case Uint32Array:
      return Math.round(a * 4294967295);
    case Uint16Array:
      return Math.round(a * 65535);
    case Uint8Array:
      return Math.round(a * 255);
    case Int32Array:
      return Math.round(a * 2147483647);
    case Int16Array:
      return Math.round(a * 32767);
    case Int8Array:
      return Math.round(a * 127);
    default:
      throw new Error("Invalid component type.");
  }
}
class Ce {
  constructor(e = 0, t = 0) {
    Ce.prototype.isVector2 = !0, this.x = e, this.y = t;
  }
  get width() {
    return this.x;
  }
  set width(e) {
    this.x = e;
  }
  get height() {
    return this.y;
  }
  set height(e) {
    this.y = e;
  }
  set(e, t) {
    return this.x = e, this.y = t, this;
  }
  setScalar(e) {
    return this.x = e, this.y = e, this;
  }
  setX(e) {
    return this.x = e, this;
  }
  setY(e) {
    return this.y = e, this;
  }
  setComponent(e, t) {
    switch (e) {
      case 0:
        this.x = t;
        break;
      case 1:
        this.y = t;
        break;
      default:
        throw new Error("index is out of range: " + e);
    }
    return this;
  }
  getComponent(e) {
    switch (e) {
      case 0:
        return this.x;
      case 1:
        return this.y;
      default:
        throw new Error("index is out of range: " + e);
    }
  }
  clone() {
    return new this.constructor(this.x, this.y);
  }
  copy(e) {
    return this.x = e.x, this.y = e.y, this;
  }
  add(e) {
    return this.x += e.x, this.y += e.y, this;
  }
  addScalar(e) {
    return this.x += e, this.y += e, this;
  }
  addVectors(e, t) {
    return this.x = e.x + t.x, this.y = e.y + t.y, this;
  }
  addScaledVector(e, t) {
    return this.x += e.x * t, this.y += e.y * t, this;
  }
  sub(e) {
    return this.x -= e.x, this.y -= e.y, this;
  }
  subScalar(e) {
    return this.x -= e, this.y -= e, this;
  }
  subVectors(e, t) {
    return this.x = e.x - t.x, this.y = e.y - t.y, this;
  }
  multiply(e) {
    return this.x *= e.x, this.y *= e.y, this;
  }
  multiplyScalar(e) {
    return this.x *= e, this.y *= e, this;
  }
  divide(e) {
    return this.x /= e.x, this.y /= e.y, this;
  }
  divideScalar(e) {
    return this.multiplyScalar(1 / e);
  }
  applyMatrix3(e) {
    const t = this.x, r = this.y, n = e.elements;
    return this.x = n[0] * t + n[3] * r + n[6], this.y = n[1] * t + n[4] * r + n[7], this;
  }
  min(e) {
    return this.x = Math.min(this.x, e.x), this.y = Math.min(this.y, e.y), this;
  }
  max(e) {
    return this.x = Math.max(this.x, e.x), this.y = Math.max(this.y, e.y), this;
  }
  clamp(e, t) {
    return this.x = Math.max(e.x, Math.min(t.x, this.x)), this.y = Math.max(e.y, Math.min(t.y, this.y)), this;
  }
  clampScalar(e, t) {
    return this.x = Math.max(e, Math.min(t, this.x)), this.y = Math.max(e, Math.min(t, this.y)), this;
  }
  clampLength(e, t) {
    const r = this.length();
    return this.divideScalar(r || 1).multiplyScalar(Math.max(e, Math.min(t, r)));
  }
  floor() {
    return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this;
  }
  ceil() {
    return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this;
  }
  round() {
    return this.x = Math.round(this.x), this.y = Math.round(this.y), this;
  }
  roundToZero() {
    return this.x = Math.trunc(this.x), this.y = Math.trunc(this.y), this;
  }
  negate() {
    return this.x = -this.x, this.y = -this.y, this;
  }
  dot(e) {
    return this.x * e.x + this.y * e.y;
  }
  cross(e) {
    return this.x * e.y - this.y * e.x;
  }
  lengthSq() {
    return this.x * this.x + this.y * this.y;
  }
  length() {
    return Math.sqrt(this.x * this.x + this.y * this.y);
  }
  manhattanLength() {
    return Math.abs(this.x) + Math.abs(this.y);
  }
  normalize() {
    return this.divideScalar(this.length() || 1);
  }
  angle() {
    return Math.atan2(-this.y, -this.x) + Math.PI;
  }
  angleTo(e) {
    const t = Math.sqrt(this.lengthSq() * e.lengthSq());
    if (t === 0) return Math.PI / 2;
    const r = this.dot(e) / t;
    return Math.acos(bt(r, -1, 1));
  }
  distanceTo(e) {
    return Math.sqrt(this.distanceToSquared(e));
  }
  distanceToSquared(e) {
    const t = this.x - e.x, r = this.y - e.y;
    return t * t + r * r;
  }
  manhattanDistanceTo(e) {
    return Math.abs(this.x - e.x) + Math.abs(this.y - e.y);
  }
  setLength(e) {
    return this.normalize().multiplyScalar(e);
  }
  lerp(e, t) {
    return this.x += (e.x - this.x) * t, this.y += (e.y - this.y) * t, this;
  }
  lerpVectors(e, t, r) {
    return this.x = e.x + (t.x - e.x) * r, this.y = e.y + (t.y - e.y) * r, this;
  }
  equals(e) {
    return e.x === this.x && e.y === this.y;
  }
  fromArray(e, t = 0) {
    return this.x = e[t], this.y = e[t + 1], this;
  }
  toArray(e = [], t = 0) {
    return e[t] = this.x, e[t + 1] = this.y, e;
  }
  fromBufferAttribute(e, t) {
    return this.x = e.getX(t), this.y = e.getY(t), this;
  }
  rotateAround(e, t) {
    const r = Math.cos(t), n = Math.sin(t), i = this.x - e.x, s = this.y - e.y;
    return this.x = i * r - s * n + e.x, this.y = i * n + s * r + e.y, this;
  }
  random() {
    return this.x = Math.random(), this.y = Math.random(), this;
  }
  *[Symbol.iterator]() {
    yield this.x, yield this.y;
  }
}
class Ye {
  constructor(e, t, r, n, i, s, o, l, c) {
    Ye.prototype.isMatrix3 = !0, this.elements = [
      1,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      1
    ], e !== void 0 && this.set(e, t, r, n, i, s, o, l, c);
  }
  set(e, t, r, n, i, s, o, l, c) {
    const u = this.elements;
    return u[0] = e, u[1] = n, u[2] = o, u[3] = t, u[4] = i, u[5] = l, u[6] = r, u[7] = s, u[8] = c, this;
  }
  identity() {
    return this.set(
      1,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      1
    ), this;
  }
  copy(e) {
    const t = this.elements, r = e.elements;
    return t[0] = r[0], t[1] = r[1], t[2] = r[2], t[3] = r[3], t[4] = r[4], t[5] = r[5], t[6] = r[6], t[7] = r[7], t[8] = r[8], this;
  }
  extractBasis(e, t, r) {
    return e.setFromMatrix3Column(this, 0), t.setFromMatrix3Column(this, 1), r.setFromMatrix3Column(this, 2), this;
  }
  setFromMatrix4(e) {
    const t = e.elements;
    return this.set(
      t[0],
      t[4],
      t[8],
      t[1],
      t[5],
      t[9],
      t[2],
      t[6],
      t[10]
    ), this;
  }
  multiply(e) {
    return this.multiplyMatrices(this, e);
  }
  premultiply(e) {
    return this.multiplyMatrices(e, this);
  }
  multiplyMatrices(e, t) {
    const r = e.elements, n = t.elements, i = this.elements, s = r[0], o = r[3], l = r[6], c = r[1], u = r[4], f = r[7], h = r[2], d = r[5], g = r[8], v = n[0], m = n[3], p = n[6], T = n[1], x = n[4], _ = n[7], D = n[2], C = n[5], A = n[8];
    return i[0] = s * v + o * T + l * D, i[3] = s * m + o * x + l * C, i[6] = s * p + o * _ + l * A, i[1] = c * v + u * T + f * D, i[4] = c * m + u * x + f * C, i[7] = c * p + u * _ + f * A, i[2] = h * v + d * T + g * D, i[5] = h * m + d * x + g * C, i[8] = h * p + d * _ + g * A, this;
  }
  multiplyScalar(e) {
    const t = this.elements;
    return t[0] *= e, t[3] *= e, t[6] *= e, t[1] *= e, t[4] *= e, t[7] *= e, t[2] *= e, t[5] *= e, t[8] *= e, this;
  }
  determinant() {
    const e = this.elements, t = e[0], r = e[1], n = e[2], i = e[3], s = e[4], o = e[5], l = e[6], c = e[7], u = e[8];
    return t * s * u - t * o * c - r * i * u + r * o * l + n * i * c - n * s * l;
  }
  invert() {
    const e = this.elements, t = e[0], r = e[1], n = e[2], i = e[3], s = e[4], o = e[5], l = e[6], c = e[7], u = e[8], f = u * s - o * c, h = o * l - u * i, d = c * i - s * l, g = t * f + r * h + n * d;
    if (g === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
    const v = 1 / g;
    return e[0] = f * v, e[1] = (n * c - u * r) * v, e[2] = (o * r - n * s) * v, e[3] = h * v, e[4] = (u * t - n * l) * v, e[5] = (n * i - o * t) * v, e[6] = d * v, e[7] = (r * l - c * t) * v, e[8] = (s * t - r * i) * v, this;
  }
  transpose() {
    let e;
    const t = this.elements;
    return e = t[1], t[1] = t[3], t[3] = e, e = t[2], t[2] = t[6], t[6] = e, e = t[5], t[5] = t[7], t[7] = e, this;
  }
  getNormalMatrix(e) {
    return this.setFromMatrix4(e).invert().transpose();
  }
  transposeIntoArray(e) {
    const t = this.elements;
    return e[0] = t[0], e[1] = t[3], e[2] = t[6], e[3] = t[1], e[4] = t[4], e[5] = t[7], e[6] = t[2], e[7] = t[5], e[8] = t[8], this;
  }
  setUvTransform(e, t, r, n, i, s, o) {
    const l = Math.cos(i), c = Math.sin(i);
    return this.set(
      r * l,
      r * c,
      -r * (l * s + c * o) + s + e,
      -n * c,
      n * l,
      -n * (-c * s + l * o) + o + t,
      0,
      0,
      1
    ), this;
  }
  //
  scale(e, t) {
    return this.premultiply(ra.makeScale(e, t)), this;
  }
  rotate(e) {
    return this.premultiply(ra.makeRotation(-e)), this;
  }
  translate(e, t) {
    return this.premultiply(ra.makeTranslation(e, t)), this;
  }
  // for 2D Transforms
  makeTranslation(e, t) {
    return e.isVector2 ? this.set(
      1,
      0,
      e.x,
      0,
      1,
      e.y,
      0,
      0,
      1
    ) : this.set(
      1,
      0,
      e,
      0,
      1,
      t,
      0,
      0,
      1
    ), this;
  }
  makeRotation(e) {
    const t = Math.cos(e), r = Math.sin(e);
    return this.set(
      t,
      -r,
      0,
      r,
      t,
      0,
      0,
      0,
      1
    ), this;
  }
  makeScale(e, t) {
    return this.set(
      e,
      0,
      0,
      0,
      t,
      0,
      0,
      0,
      1
    ), this;
  }
  //
  equals(e) {
    const t = this.elements, r = e.elements;
    for (let n = 0; n < 9; n++)
      if (t[n] !== r[n]) return !1;
    return !0;
  }
  fromArray(e, t = 0) {
    for (let r = 0; r < 9; r++)
      this.elements[r] = e[r + t];
    return this;
  }
  toArray(e = [], t = 0) {
    const r = this.elements;
    return e[t] = r[0], e[t + 1] = r[1], e[t + 2] = r[2], e[t + 3] = r[3], e[t + 4] = r[4], e[t + 5] = r[5], e[t + 6] = r[6], e[t + 7] = r[7], e[t + 8] = r[8], e;
  }
  clone() {
    return new this.constructor().fromArray(this.elements);
  }
}
const ra = /* @__PURE__ */ new Ye();
function Io(a) {
  for (let e = a.length - 1; e >= 0; --e)
    if (a[e] >= 65535) return !0;
  return !1;
}
function Nr(a) {
  return document.createElementNS("http://www.w3.org/1999/xhtml", a);
}
function bl() {
  const a = Nr("canvas");
  return a.style.display = "block", a;
}
const xs = {};
function Ni(a) {
  a in xs || (xs[a] = !0, console.warn(a));
}
function Al(a, e, t) {
  return new Promise(function(r, n) {
    function i() {
      switch (a.clientWaitSync(e, a.SYNC_FLUSH_COMMANDS_BIT, 0)) {
        case a.WAIT_FAILED:
          n();
          break;
        case a.TIMEOUT_EXPIRED:
          setTimeout(i, t);
          break;
        default:
          r();
      }
    }
    setTimeout(i, t);
  });
}
function wl(a) {
  const e = a.elements;
  e[2] = 0.5 * e[2] + 0.5 * e[3], e[6] = 0.5 * e[6] + 0.5 * e[7], e[10] = 0.5 * e[10] + 0.5 * e[11], e[14] = 0.5 * e[14] + 0.5 * e[15];
}
function Cl(a) {
  const e = a.elements;
  e[11] === -1 ? (e[10] = -e[10] - 1, e[14] = -e[14]) : (e[10] = -e[10], e[14] = -e[14] + 1);
}
const $e = {
  enabled: !0,
  workingColorSpace: pi,
  /**
   * Implementations of supported color spaces.
   *
   * Required:
   *	- primaries: chromaticity coordinates [ rx ry gx gy bx by ]
   *	- whitePoint: reference white [ x y ]
   *	- transfer: transfer function (pre-defined)
   *	- toXYZ: Matrix3 RGB to XYZ transform
   *	- fromXYZ: Matrix3 XYZ to RGB transform
   *	- luminanceCoefficients: RGB luminance coefficients
   *
   * Optional:
   *  - outputColorSpaceConfig: { drawingBufferColorSpace: ColorSpace }
   *  - workingColorSpaceConfig: { unpackColorSpace: ColorSpace }
   *
   * Reference:
   * - https://www.russellcottrell.com/photo/matrixCalculator.htm
   */
  spaces: {},
  convert: function(a, e, t) {
    return this.enabled === !1 || e === t || !e || !t || (this.spaces[e].transfer === it && (a.r = pn(a.r), a.g = pn(a.g), a.b = pn(a.b)), this.spaces[e].primaries !== this.spaces[t].primaries && (a.applyMatrix3(this.spaces[e].toXYZ), a.applyMatrix3(this.spaces[t].fromXYZ)), this.spaces[t].transfer === it && (a.r = hi(a.r), a.g = hi(a.g), a.b = hi(a.b))), a;
  },
  fromWorkingColorSpace: function(a, e) {
    return this.convert(a, this.workingColorSpace, e);
  },
  toWorkingColorSpace: function(a, e) {
    return this.convert(a, e, this.workingColorSpace);
  },
  getPrimaries: function(a) {
    return this.spaces[a].primaries;
  },
  getTransfer: function(a) {
    return a === Tn ? kr : this.spaces[a].transfer;
  },
  getLuminanceCoefficients: function(a, e = this.workingColorSpace) {
    return a.fromArray(this.spaces[e].luminanceCoefficients);
  },
  define: function(a) {
    Object.assign(this.spaces, a);
  },
  // Internal APIs
  _getMatrix: function(a, e, t) {
    return a.copy(this.spaces[e].toXYZ).multiply(this.spaces[t].fromXYZ);
  },
  _getDrawingBufferColorSpace: function(a) {
    return this.spaces[a].outputColorSpaceConfig.drawingBufferColorSpace;
  },
  _getUnpackColorSpace: function(a = this.workingColorSpace) {
    return this.spaces[a].workingColorSpaceConfig.unpackColorSpace;
  }
};
function pn(a) {
  return a < 0.04045 ? a * 0.0773993808 : Math.pow(a * 0.9478672986 + 0.0521327014, 2.4);
}
function hi(a) {
  return a < 31308e-7 ? a * 12.92 : 1.055 * Math.pow(a, 0.41666) - 0.055;
}
const Ss = [0.64, 0.33, 0.3, 0.6, 0.15, 0.06], ys = [0.2126, 0.7152, 0.0722], Ms = [0.3127, 0.329], Es = /* @__PURE__ */ new Ye().set(
  0.4123908,
  0.3575843,
  0.1804808,
  0.212639,
  0.7151687,
  0.0721923,
  0.0193308,
  0.1191948,
  0.9505322
), Ts = /* @__PURE__ */ new Ye().set(
  3.2409699,
  -1.5373832,
  -0.4986108,
  -0.9692436,
  1.8759675,
  0.0415551,
  0.0556301,
  -0.203977,
  1.0569715
);
$e.define({
  [pi]: {
    primaries: Ss,
    whitePoint: Ms,
    transfer: kr,
    toXYZ: Es,
    fromXYZ: Ts,
    luminanceCoefficients: ys,
    workingColorSpaceConfig: { unpackColorSpace: Xt },
    outputColorSpaceConfig: { drawingBufferColorSpace: Xt }
  },
  [Xt]: {
    primaries: Ss,
    whitePoint: Ms,
    transfer: it,
    toXYZ: Es,
    fromXYZ: Ts,
    luminanceCoefficients: ys,
    outputColorSpaceConfig: { drawingBufferColorSpace: Xt }
  }
});
let qn;
class Rl {
  static getDataURL(e) {
    if (/^data:/i.test(e.src) || typeof HTMLCanvasElement > "u")
      return e.src;
    let t;
    if (e instanceof HTMLCanvasElement)
      t = e;
    else {
      qn === void 0 && (qn = Nr("canvas")), qn.width = e.width, qn.height = e.height;
      const r = qn.getContext("2d");
      e instanceof ImageData ? r.putImageData(e, 0, 0) : r.drawImage(e, 0, 0, e.width, e.height), t = qn;
    }
    return t.width > 2048 || t.height > 2048 ? (console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons", e), t.toDataURL("image/jpeg", 0.6)) : t.toDataURL("image/png");
  }
  static sRGBToLinear(e) {
    if (typeof HTMLImageElement < "u" && e instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && e instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && e instanceof ImageBitmap) {
      const t = Nr("canvas");
      t.width = e.width, t.height = e.height;
      const r = t.getContext("2d");
      r.drawImage(e, 0, 0, e.width, e.height);
      const n = r.getImageData(0, 0, e.width, e.height), i = n.data;
      for (let s = 0; s < i.length; s++)
        i[s] = pn(i[s] / 255) * 255;
      return r.putImageData(n, 0, 0), t;
    } else if (e.data) {
      const t = e.data.slice(0);
      for (let r = 0; r < t.length; r++)
        t instanceof Uint8Array || t instanceof Uint8ClampedArray ? t[r] = Math.floor(pn(t[r] / 255) * 255) : t[r] = pn(t[r]);
      return {
        data: t,
        width: e.width,
        height: e.height
      };
    } else
      return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."), e;
  }
}
let Pl = 0;
class No {
  constructor(e = null) {
    this.isSource = !0, Object.defineProperty(this, "id", { value: Pl++ }), this.uuid = mi(), this.data = e, this.dataReady = !0, this.version = 0;
  }
  set needsUpdate(e) {
    e === !0 && this.version++;
  }
  toJSON(e) {
    const t = e === void 0 || typeof e == "string";
    if (!t && e.images[this.uuid] !== void 0)
      return e.images[this.uuid];
    const r = {
      uuid: this.uuid,
      url: ""
    }, n = this.data;
    if (n !== null) {
      let i;
      if (Array.isArray(n)) {
        i = [];
        for (let s = 0, o = n.length; s < o; s++)
          n[s].isDataTexture ? i.push(aa(n[s].image)) : i.push(aa(n[s]));
      } else
        i = aa(n);
      r.url = i;
    }
    return t || (e.images[this.uuid] = r), r;
  }
}
function aa(a) {
  return typeof HTMLImageElement < "u" && a instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && a instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && a instanceof ImageBitmap ? Rl.getDataURL(a) : a.data ? {
    data: Array.from(a.data),
    width: a.width,
    height: a.height,
    type: a.data.constructor.name
  } : (console.warn("THREE.Texture: Unable to serialize Texture."), {});
}
let Ul = 0;
class wt extends Gn {
  constructor(e = wt.DEFAULT_IMAGE, t = wt.DEFAULT_MAPPING, r = 1001, n = 1001, i = 1006, s = 1008, o = 1023, l = 1009, c = wt.DEFAULT_ANISOTROPY, u = Tn) {
    super(), this.isTexture = !0, Object.defineProperty(this, "id", { value: Ul++ }), this.uuid = mi(), this.name = "", this.source = new No(e), this.mipmaps = [], this.mapping = t, this.channel = 0, this.wrapS = r, this.wrapT = n, this.magFilter = i, this.minFilter = s, this.anisotropy = c, this.format = o, this.internalFormat = null, this.type = l, this.offset = new Ce(0, 0), this.repeat = new Ce(1, 1), this.center = new Ce(0, 0), this.rotation = 0, this.matrixAutoUpdate = !0, this.matrix = new Ye(), this.generateMipmaps = !0, this.premultiplyAlpha = !1, this.flipY = !0, this.unpackAlignment = 4, this.colorSpace = u, this.userData = {}, this.version = 0, this.onUpdate = null, this.isRenderTargetTexture = !1, this.pmremVersion = 0;
  }
  get image() {
    return this.source.data;
  }
  set image(e = null) {
    this.source.data = e;
  }
  updateMatrix() {
    this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  }
  clone() {
    return new this.constructor().copy(this);
  }
  copy(e) {
    return this.name = e.name, this.source = e.source, this.mipmaps = e.mipmaps.slice(0), this.mapping = e.mapping, this.channel = e.channel, this.wrapS = e.wrapS, this.wrapT = e.wrapT, this.magFilter = e.magFilter, this.minFilter = e.minFilter, this.anisotropy = e.anisotropy, this.format = e.format, this.internalFormat = e.internalFormat, this.type = e.type, this.offset.copy(e.offset), this.repeat.copy(e.repeat), this.center.copy(e.center), this.rotation = e.rotation, this.matrixAutoUpdate = e.matrixAutoUpdate, this.matrix.copy(e.matrix), this.generateMipmaps = e.generateMipmaps, this.premultiplyAlpha = e.premultiplyAlpha, this.flipY = e.flipY, this.unpackAlignment = e.unpackAlignment, this.colorSpace = e.colorSpace, this.userData = JSON.parse(JSON.stringify(e.userData)), this.needsUpdate = !0, this;
  }
  toJSON(e) {
    const t = e === void 0 || typeof e == "string";
    if (!t && e.textures[this.uuid] !== void 0)
      return e.textures[this.uuid];
    const r = {
      metadata: {
        version: 4.6,
        type: "Texture",
        generator: "Texture.toJSON"
      },
      uuid: this.uuid,
      name: this.name,
      image: this.source.toJSON(e).uuid,
      mapping: this.mapping,
      channel: this.channel,
      repeat: [this.repeat.x, this.repeat.y],
      offset: [this.offset.x, this.offset.y],
      center: [this.center.x, this.center.y],
      rotation: this.rotation,
      wrap: [this.wrapS, this.wrapT],
      format: this.format,
      internalFormat: this.internalFormat,
      type: this.type,
      colorSpace: this.colorSpace,
      minFilter: this.minFilter,
      magFilter: this.magFilter,
      anisotropy: this.anisotropy,
      flipY: this.flipY,
      generateMipmaps: this.generateMipmaps,
      premultiplyAlpha: this.premultiplyAlpha,
      unpackAlignment: this.unpackAlignment
    };
    return Object.keys(this.userData).length > 0 && (r.userData = this.userData), t || (e.textures[this.uuid] = r), r;
  }
  dispose() {
    this.dispatchEvent({ type: "dispose" });
  }
  transformUv(e) {
    if (this.mapping !== 300) return e;
    if (e.applyMatrix3(this.matrix), e.x < 0 || e.x > 1)
      switch (this.wrapS) {
        case 1e3:
          e.x = e.x - Math.floor(e.x);
          break;
        case 1001:
          e.x = e.x < 0 ? 0 : 1;
          break;
        case 1002:
          Math.abs(Math.floor(e.x) % 2) === 1 ? e.x = Math.ceil(e.x) - e.x : e.x = e.x - Math.floor(e.x);
          break;
      }
    if (e.y < 0 || e.y > 1)
      switch (this.wrapT) {
        case 1e3:
          e.y = e.y - Math.floor(e.y);
          break;
        case 1001:
          e.y = e.y < 0 ? 0 : 1;
          break;
        case 1002:
          Math.abs(Math.floor(e.y) % 2) === 1 ? e.y = Math.ceil(e.y) - e.y : e.y = e.y - Math.floor(e.y);
          break;
      }
    return this.flipY && (e.y = 1 - e.y), e;
  }
  set needsUpdate(e) {
    e === !0 && (this.version++, this.source.needsUpdate = !0);
  }
  set needsPMREMUpdate(e) {
    e === !0 && this.pmremVersion++;
  }
}
wt.DEFAULT_IMAGE = null;
wt.DEFAULT_MAPPING = 300;
wt.DEFAULT_ANISOTROPY = 1;
class ot {
  constructor(e = 0, t = 0, r = 0, n = 1) {
    ot.prototype.isVector4 = !0, this.x = e, this.y = t, this.z = r, this.w = n;
  }
  get width() {
    return this.z;
  }
  set width(e) {
    this.z = e;
  }
  get height() {
    return this.w;
  }
  set height(e) {
    this.w = e;
  }
  set(e, t, r, n) {
    return this.x = e, this.y = t, this.z = r, this.w = n, this;
  }
  setScalar(e) {
    return this.x = e, this.y = e, this.z = e, this.w = e, this;
  }
  setX(e) {
    return this.x = e, this;
  }
  setY(e) {
    return this.y = e, this;
  }
  setZ(e) {
    return this.z = e, this;
  }
  setW(e) {
    return this.w = e, this;
  }
  setComponent(e, t) {
    switch (e) {
      case 0:
        this.x = t;
        break;
      case 1:
        this.y = t;
        break;
      case 2:
        this.z = t;
        break;
      case 3:
        this.w = t;
        break;
      default:
        throw new Error("index is out of range: " + e);
    }
    return this;
  }
  getComponent(e) {
    switch (e) {
      case 0:
        return this.x;
      case 1:
        return this.y;
      case 2:
        return this.z;
      case 3:
        return this.w;
      default:
        throw new Error("index is out of range: " + e);
    }
  }
  clone() {
    return new this.constructor(this.x, this.y, this.z, this.w);
  }
  copy(e) {
    return this.x = e.x, this.y = e.y, this.z = e.z, this.w = e.w !== void 0 ? e.w : 1, this;
  }
  add(e) {
    return this.x += e.x, this.y += e.y, this.z += e.z, this.w += e.w, this;
  }
  addScalar(e) {
    return this.x += e, this.y += e, this.z += e, this.w += e, this;
  }
  addVectors(e, t) {
    return this.x = e.x + t.x, this.y = e.y + t.y, this.z = e.z + t.z, this.w = e.w + t.w, this;
  }
  addScaledVector(e, t) {
    return this.x += e.x * t, this.y += e.y * t, this.z += e.z * t, this.w += e.w * t, this;
  }
  sub(e) {
    return this.x -= e.x, this.y -= e.y, this.z -= e.z, this.w -= e.w, this;
  }
  subScalar(e) {
    return this.x -= e, this.y -= e, this.z -= e, this.w -= e, this;
  }
  subVectors(e, t) {
    return this.x = e.x - t.x, this.y = e.y - t.y, this.z = e.z - t.z, this.w = e.w - t.w, this;
  }
  multiply(e) {
    return this.x *= e.x, this.y *= e.y, this.z *= e.z, this.w *= e.w, this;
  }
  multiplyScalar(e) {
    return this.x *= e, this.y *= e, this.z *= e, this.w *= e, this;
  }
  applyMatrix4(e) {
    const t = this.x, r = this.y, n = this.z, i = this.w, s = e.elements;
    return this.x = s[0] * t + s[4] * r + s[8] * n + s[12] * i, this.y = s[1] * t + s[5] * r + s[9] * n + s[13] * i, this.z = s[2] * t + s[6] * r + s[10] * n + s[14] * i, this.w = s[3] * t + s[7] * r + s[11] * n + s[15] * i, this;
  }
  divide(e) {
    return this.x /= e.x, this.y /= e.y, this.z /= e.z, this.w /= e.w, this;
  }
  divideScalar(e) {
    return this.multiplyScalar(1 / e);
  }
  setAxisAngleFromQuaternion(e) {
    this.w = 2 * Math.acos(e.w);
    const t = Math.sqrt(1 - e.w * e.w);
    return t < 1e-4 ? (this.x = 1, this.y = 0, this.z = 0) : (this.x = e.x / t, this.y = e.y / t, this.z = e.z / t), this;
  }
  setAxisAngleFromRotationMatrix(e) {
    let t, r, n, i;
    const l = e.elements, c = l[0], u = l[4], f = l[8], h = l[1], d = l[5], g = l[9], v = l[2], m = l[6], p = l[10];
    if (Math.abs(u - h) < 0.01 && Math.abs(f - v) < 0.01 && Math.abs(g - m) < 0.01) {
      if (Math.abs(u + h) < 0.1 && Math.abs(f + v) < 0.1 && Math.abs(g + m) < 0.1 && Math.abs(c + d + p - 3) < 0.1)
        return this.set(1, 0, 0, 0), this;
      t = Math.PI;
      const x = (c + 1) / 2, _ = (d + 1) / 2, D = (p + 1) / 2, C = (u + h) / 4, A = (f + v) / 4, R = (g + m) / 4;
      return x > _ && x > D ? x < 0.01 ? (r = 0, n = 0.707106781, i = 0.707106781) : (r = Math.sqrt(x), n = C / r, i = A / r) : _ > D ? _ < 0.01 ? (r = 0.707106781, n = 0, i = 0.707106781) : (n = Math.sqrt(_), r = C / n, i = R / n) : D < 0.01 ? (r = 0.707106781, n = 0.707106781, i = 0) : (i = Math.sqrt(D), r = A / i, n = R / i), this.set(r, n, i, t), this;
    }
    let T = Math.sqrt((m - g) * (m - g) + (f - v) * (f - v) + (h - u) * (h - u));
    return Math.abs(T) < 1e-3 && (T = 1), this.x = (m - g) / T, this.y = (f - v) / T, this.z = (h - u) / T, this.w = Math.acos((c + d + p - 1) / 2), this;
  }
  setFromMatrixPosition(e) {
    const t = e.elements;
    return this.x = t[12], this.y = t[13], this.z = t[14], this.w = t[15], this;
  }
  min(e) {
    return this.x = Math.min(this.x, e.x), this.y = Math.min(this.y, e.y), this.z = Math.min(this.z, e.z), this.w = Math.min(this.w, e.w), this;
  }
  max(e) {
    return this.x = Math.max(this.x, e.x), this.y = Math.max(this.y, e.y), this.z = Math.max(this.z, e.z), this.w = Math.max(this.w, e.w), this;
  }
  clamp(e, t) {
    return this.x = Math.max(e.x, Math.min(t.x, this.x)), this.y = Math.max(e.y, Math.min(t.y, this.y)), this.z = Math.max(e.z, Math.min(t.z, this.z)), this.w = Math.max(e.w, Math.min(t.w, this.w)), this;
  }
  clampScalar(e, t) {
    return this.x = Math.max(e, Math.min(t, this.x)), this.y = Math.max(e, Math.min(t, this.y)), this.z = Math.max(e, Math.min(t, this.z)), this.w = Math.max(e, Math.min(t, this.w)), this;
  }
  clampLength(e, t) {
    const r = this.length();
    return this.divideScalar(r || 1).multiplyScalar(Math.max(e, Math.min(t, r)));
  }
  floor() {
    return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this.z = Math.floor(this.z), this.w = Math.floor(this.w), this;
  }
  ceil() {
    return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this.z = Math.ceil(this.z), this.w = Math.ceil(this.w), this;
  }
  round() {
    return this.x = Math.round(this.x), this.y = Math.round(this.y), this.z = Math.round(this.z), this.w = Math.round(this.w), this;
  }
  roundToZero() {
    return this.x = Math.trunc(this.x), this.y = Math.trunc(this.y), this.z = Math.trunc(this.z), this.w = Math.trunc(this.w), this;
  }
  negate() {
    return this.x = -this.x, this.y = -this.y, this.z = -this.z, this.w = -this.w, this;
  }
  dot(e) {
    return this.x * e.x + this.y * e.y + this.z * e.z + this.w * e.w;
  }
  lengthSq() {
    return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  }
  length() {
    return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  }
  manhattanLength() {
    return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  }
  normalize() {
    return this.divideScalar(this.length() || 1);
  }
  setLength(e) {
    return this.normalize().multiplyScalar(e);
  }
  lerp(e, t) {
    return this.x += (e.x - this.x) * t, this.y += (e.y - this.y) * t, this.z += (e.z - this.z) * t, this.w += (e.w - this.w) * t, this;
  }
  lerpVectors(e, t, r) {
    return this.x = e.x + (t.x - e.x) * r, this.y = e.y + (t.y - e.y) * r, this.z = e.z + (t.z - e.z) * r, this.w = e.w + (t.w - e.w) * r, this;
  }
  equals(e) {
    return e.x === this.x && e.y === this.y && e.z === this.z && e.w === this.w;
  }
  fromArray(e, t = 0) {
    return this.x = e[t], this.y = e[t + 1], this.z = e[t + 2], this.w = e[t + 3], this;
  }
  toArray(e = [], t = 0) {
    return e[t] = this.x, e[t + 1] = this.y, e[t + 2] = this.z, e[t + 3] = this.w, e;
  }
  fromBufferAttribute(e, t) {
    return this.x = e.getX(t), this.y = e.getY(t), this.z = e.getZ(t), this.w = e.getW(t), this;
  }
  random() {
    return this.x = Math.random(), this.y = Math.random(), this.z = Math.random(), this.w = Math.random(), this;
  }
  *[Symbol.iterator]() {
    yield this.x, yield this.y, yield this.z, yield this.w;
  }
}
class Dl extends Gn {
  constructor(e = 1, t = 1, r = {}) {
    super(), this.isRenderTarget = !0, this.width = e, this.height = t, this.depth = 1, this.scissor = new ot(0, 0, e, t), this.scissorTest = !1, this.viewport = new ot(0, 0, e, t);
    const n = { width: e, height: t, depth: 1 };
    r = Object.assign({
      generateMipmaps: !1,
      internalFormat: null,
      minFilter: 1006,
      depthBuffer: !0,
      stencilBuffer: !1,
      resolveDepthBuffer: !0,
      resolveStencilBuffer: !0,
      depthTexture: null,
      samples: 0,
      count: 1
    }, r);
    const i = new wt(n, r.mapping, r.wrapS, r.wrapT, r.magFilter, r.minFilter, r.format, r.type, r.anisotropy, r.colorSpace);
    i.flipY = !1, i.generateMipmaps = r.generateMipmaps, i.internalFormat = r.internalFormat, this.textures = [];
    const s = r.count;
    for (let o = 0; o < s; o++)
      this.textures[o] = i.clone(), this.textures[o].isRenderTargetTexture = !0;
    this.depthBuffer = r.depthBuffer, this.stencilBuffer = r.stencilBuffer, this.resolveDepthBuffer = r.resolveDepthBuffer, this.resolveStencilBuffer = r.resolveStencilBuffer, this.depthTexture = r.depthTexture, this.samples = r.samples;
  }
  get texture() {
    return this.textures[0];
  }
  set texture(e) {
    this.textures[0] = e;
  }
  setSize(e, t, r = 1) {
    if (this.width !== e || this.height !== t || this.depth !== r) {
      this.width = e, this.height = t, this.depth = r;
      for (let n = 0, i = this.textures.length; n < i; n++)
        this.textures[n].image.width = e, this.textures[n].image.height = t, this.textures[n].image.depth = r;
      this.dispose();
    }
    this.viewport.set(0, 0, e, t), this.scissor.set(0, 0, e, t);
  }
  clone() {
    return new this.constructor().copy(this);
  }
  copy(e) {
    this.width = e.width, this.height = e.height, this.depth = e.depth, this.scissor.copy(e.scissor), this.scissorTest = e.scissorTest, this.viewport.copy(e.viewport), this.textures.length = 0;
    for (let r = 0, n = e.textures.length; r < n; r++)
      this.textures[r] = e.textures[r].clone(), this.textures[r].isRenderTargetTexture = !0;
    const t = Object.assign({}, e.texture.image);
    return this.texture.source = new No(t), this.depthBuffer = e.depthBuffer, this.stencilBuffer = e.stencilBuffer, this.resolveDepthBuffer = e.resolveDepthBuffer, this.resolveStencilBuffer = e.resolveStencilBuffer, e.depthTexture !== null && (this.depthTexture = e.depthTexture.clone()), this.samples = e.samples, this;
  }
  dispose() {
    this.dispatchEvent({ type: "dispose" });
  }
}
class Bn extends Dl {
  constructor(e = 1, t = 1, r = {}) {
    super(e, t, r), this.isWebGLRenderTarget = !0;
  }
}
class Oo extends wt {
  constructor(e = null, t = 1, r = 1, n = 1) {
    super(null), this.isDataArrayTexture = !0, this.image = { data: e, width: t, height: r, depth: n }, this.magFilter = 1003, this.minFilter = 1003, this.wrapR = 1001, this.generateMipmaps = !1, this.flipY = !1, this.unpackAlignment = 1, this.layerUpdates = /* @__PURE__ */ new Set();
  }
  addLayerUpdate(e) {
    this.layerUpdates.add(e);
  }
  clearLayerUpdates() {
    this.layerUpdates.clear();
  }
}
class Ll extends wt {
  constructor(e = null, t = 1, r = 1, n = 1) {
    super(null), this.isData3DTexture = !0, this.image = { data: e, width: t, height: r, depth: n }, this.magFilter = 1003, this.minFilter = 1003, this.wrapR = 1001, this.generateMipmaps = !1, this.flipY = !1, this.unpackAlignment = 1;
  }
}
class qi {
  constructor(e = 0, t = 0, r = 0, n = 1) {
    this.isQuaternion = !0, this._x = e, this._y = t, this._z = r, this._w = n;
  }
  static slerpFlat(e, t, r, n, i, s, o) {
    let l = r[n + 0], c = r[n + 1], u = r[n + 2], f = r[n + 3];
    const h = i[s + 0], d = i[s + 1], g = i[s + 2], v = i[s + 3];
    if (o === 0) {
      e[t + 0] = l, e[t + 1] = c, e[t + 2] = u, e[t + 3] = f;
      return;
    }
    if (o === 1) {
      e[t + 0] = h, e[t + 1] = d, e[t + 2] = g, e[t + 3] = v;
      return;
    }
    if (f !== v || l !== h || c !== d || u !== g) {
      let m = 1 - o;
      const p = l * h + c * d + u * g + f * v, T = p >= 0 ? 1 : -1, x = 1 - p * p;
      if (x > Number.EPSILON) {
        const D = Math.sqrt(x), C = Math.atan2(D, p * T);
        m = Math.sin(m * C) / D, o = Math.sin(o * C) / D;
      }
      const _ = o * T;
      if (l = l * m + h * _, c = c * m + d * _, u = u * m + g * _, f = f * m + v * _, m === 1 - o) {
        const D = 1 / Math.sqrt(l * l + c * c + u * u + f * f);
        l *= D, c *= D, u *= D, f *= D;
      }
    }
    e[t] = l, e[t + 1] = c, e[t + 2] = u, e[t + 3] = f;
  }
  static multiplyQuaternionsFlat(e, t, r, n, i, s) {
    const o = r[n], l = r[n + 1], c = r[n + 2], u = r[n + 3], f = i[s], h = i[s + 1], d = i[s + 2], g = i[s + 3];
    return e[t] = o * g + u * f + l * d - c * h, e[t + 1] = l * g + u * h + c * f - o * d, e[t + 2] = c * g + u * d + o * h - l * f, e[t + 3] = u * g - o * f - l * h - c * d, e;
  }
  get x() {
    return this._x;
  }
  set x(e) {
    this._x = e, this._onChangeCallback();
  }
  get y() {
    return this._y;
  }
  set y(e) {
    this._y = e, this._onChangeCallback();
  }
  get z() {
    return this._z;
  }
  set z(e) {
    this._z = e, this._onChangeCallback();
  }
  get w() {
    return this._w;
  }
  set w(e) {
    this._w = e, this._onChangeCallback();
  }
  set(e, t, r, n) {
    return this._x = e, this._y = t, this._z = r, this._w = n, this._onChangeCallback(), this;
  }
  clone() {
    return new this.constructor(this._x, this._y, this._z, this._w);
  }
  copy(e) {
    return this._x = e.x, this._y = e.y, this._z = e.z, this._w = e.w, this._onChangeCallback(), this;
  }
  setFromEuler(e, t = !0) {
    const r = e._x, n = e._y, i = e._z, s = e._order, o = Math.cos, l = Math.sin, c = o(r / 2), u = o(n / 2), f = o(i / 2), h = l(r / 2), d = l(n / 2), g = l(i / 2);
    switch (s) {
      case "XYZ":
        this._x = h * u * f + c * d * g, this._y = c * d * f - h * u * g, this._z = c * u * g + h * d * f, this._w = c * u * f - h * d * g;
        break;
      case "YXZ":
        this._x = h * u * f + c * d * g, this._y = c * d * f - h * u * g, this._z = c * u * g - h * d * f, this._w = c * u * f + h * d * g;
        break;
      case "ZXY":
        this._x = h * u * f - c * d * g, this._y = c * d * f + h * u * g, this._z = c * u * g + h * d * f, this._w = c * u * f - h * d * g;
        break;
      case "ZYX":
        this._x = h * u * f - c * d * g, this._y = c * d * f + h * u * g, this._z = c * u * g - h * d * f, this._w = c * u * f + h * d * g;
        break;
      case "YZX":
        this._x = h * u * f + c * d * g, this._y = c * d * f + h * u * g, this._z = c * u * g - h * d * f, this._w = c * u * f - h * d * g;
        break;
      case "XZY":
        this._x = h * u * f - c * d * g, this._y = c * d * f - h * u * g, this._z = c * u * g + h * d * f, this._w = c * u * f + h * d * g;
        break;
      default:
        console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: " + s);
    }
    return t === !0 && this._onChangeCallback(), this;
  }
  setFromAxisAngle(e, t) {
    const r = t / 2, n = Math.sin(r);
    return this._x = e.x * n, this._y = e.y * n, this._z = e.z * n, this._w = Math.cos(r), this._onChangeCallback(), this;
  }
  setFromRotationMatrix(e) {
    const t = e.elements, r = t[0], n = t[4], i = t[8], s = t[1], o = t[5], l = t[9], c = t[2], u = t[6], f = t[10], h = r + o + f;
    if (h > 0) {
      const d = 0.5 / Math.sqrt(h + 1);
      this._w = 0.25 / d, this._x = (u - l) * d, this._y = (i - c) * d, this._z = (s - n) * d;
    } else if (r > o && r > f) {
      const d = 2 * Math.sqrt(1 + r - o - f);
      this._w = (u - l) / d, this._x = 0.25 * d, this._y = (n + s) / d, this._z = (i + c) / d;
    } else if (o > f) {
      const d = 2 * Math.sqrt(1 + o - r - f);
      this._w = (i - c) / d, this._x = (n + s) / d, this._y = 0.25 * d, this._z = (l + u) / d;
    } else {
      const d = 2 * Math.sqrt(1 + f - r - o);
      this._w = (s - n) / d, this._x = (i + c) / d, this._y = (l + u) / d, this._z = 0.25 * d;
    }
    return this._onChangeCallback(), this;
  }
  setFromUnitVectors(e, t) {
    let r = e.dot(t) + 1;
    return r < Number.EPSILON ? (r = 0, Math.abs(e.x) > Math.abs(e.z) ? (this._x = -e.y, this._y = e.x, this._z = 0, this._w = r) : (this._x = 0, this._y = -e.z, this._z = e.y, this._w = r)) : (this._x = e.y * t.z - e.z * t.y, this._y = e.z * t.x - e.x * t.z, this._z = e.x * t.y - e.y * t.x, this._w = r), this.normalize();
  }
  angleTo(e) {
    return 2 * Math.acos(Math.abs(bt(this.dot(e), -1, 1)));
  }
  rotateTowards(e, t) {
    const r = this.angleTo(e);
    if (r === 0) return this;
    const n = Math.min(1, t / r);
    return this.slerp(e, n), this;
  }
  identity() {
    return this.set(0, 0, 0, 1);
  }
  invert() {
    return this.conjugate();
  }
  conjugate() {
    return this._x *= -1, this._y *= -1, this._z *= -1, this._onChangeCallback(), this;
  }
  dot(e) {
    return this._x * e._x + this._y * e._y + this._z * e._z + this._w * e._w;
  }
  lengthSq() {
    return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  }
  length() {
    return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  }
  normalize() {
    let e = this.length();
    return e === 0 ? (this._x = 0, this._y = 0, this._z = 0, this._w = 1) : (e = 1 / e, this._x = this._x * e, this._y = this._y * e, this._z = this._z * e, this._w = this._w * e), this._onChangeCallback(), this;
  }
  multiply(e) {
    return this.multiplyQuaternions(this, e);
  }
  premultiply(e) {
    return this.multiplyQuaternions(e, this);
  }
  multiplyQuaternions(e, t) {
    const r = e._x, n = e._y, i = e._z, s = e._w, o = t._x, l = t._y, c = t._z, u = t._w;
    return this._x = r * u + s * o + n * c - i * l, this._y = n * u + s * l + i * o - r * c, this._z = i * u + s * c + r * l - n * o, this._w = s * u - r * o - n * l - i * c, this._onChangeCallback(), this;
  }
  slerp(e, t) {
    if (t === 0) return this;
    if (t === 1) return this.copy(e);
    const r = this._x, n = this._y, i = this._z, s = this._w;
    let o = s * e._w + r * e._x + n * e._y + i * e._z;
    if (o < 0 ? (this._w = -e._w, this._x = -e._x, this._y = -e._y, this._z = -e._z, o = -o) : this.copy(e), o >= 1)
      return this._w = s, this._x = r, this._y = n, this._z = i, this;
    const l = 1 - o * o;
    if (l <= Number.EPSILON) {
      const d = 1 - t;
      return this._w = d * s + t * this._w, this._x = d * r + t * this._x, this._y = d * n + t * this._y, this._z = d * i + t * this._z, this.normalize(), this;
    }
    const c = Math.sqrt(l), u = Math.atan2(c, o), f = Math.sin((1 - t) * u) / c, h = Math.sin(t * u) / c;
    return this._w = s * f + this._w * h, this._x = r * f + this._x * h, this._y = n * f + this._y * h, this._z = i * f + this._z * h, this._onChangeCallback(), this;
  }
  slerpQuaternions(e, t, r) {
    return this.copy(e).slerp(t, r);
  }
  random() {
    const e = 2 * Math.PI * Math.random(), t = 2 * Math.PI * Math.random(), r = Math.random(), n = Math.sqrt(1 - r), i = Math.sqrt(r);
    return this.set(
      n * Math.sin(e),
      n * Math.cos(e),
      i * Math.sin(t),
      i * Math.cos(t)
    );
  }
  equals(e) {
    return e._x === this._x && e._y === this._y && e._z === this._z && e._w === this._w;
  }
  fromArray(e, t = 0) {
    return this._x = e[t], this._y = e[t + 1], this._z = e[t + 2], this._w = e[t + 3], this._onChangeCallback(), this;
  }
  toArray(e = [], t = 0) {
    return e[t] = this._x, e[t + 1] = this._y, e[t + 2] = this._z, e[t + 3] = this._w, e;
  }
  fromBufferAttribute(e, t) {
    return this._x = e.getX(t), this._y = e.getY(t), this._z = e.getZ(t), this._w = e.getW(t), this._onChangeCallback(), this;
  }
  toJSON() {
    return this.toArray();
  }
  _onChange(e) {
    return this._onChangeCallback = e, this;
  }
  _onChangeCallback() {
  }
  *[Symbol.iterator]() {
    yield this._x, yield this._y, yield this._z, yield this._w;
  }
}
class j {
  constructor(e = 0, t = 0, r = 0) {
    j.prototype.isVector3 = !0, this.x = e, this.y = t, this.z = r;
  }
  set(e, t, r) {
    return r === void 0 && (r = this.z), this.x = e, this.y = t, this.z = r, this;
  }
  setScalar(e) {
    return this.x = e, this.y = e, this.z = e, this;
  }
  setX(e) {
    return this.x = e, this;
  }
  setY(e) {
    return this.y = e, this;
  }
  setZ(e) {
    return this.z = e, this;
  }
  setComponent(e, t) {
    switch (e) {
      case 0:
        this.x = t;
        break;
      case 1:
        this.y = t;
        break;
      case 2:
        this.z = t;
        break;
      default:
        throw new Error("index is out of range: " + e);
    }
    return this;
  }
  getComponent(e) {
    switch (e) {
      case 0:
        return this.x;
      case 1:
        return this.y;
      case 2:
        return this.z;
      default:
        throw new Error("index is out of range: " + e);
    }
  }
  clone() {
    return new this.constructor(this.x, this.y, this.z);
  }
  copy(e) {
    return this.x = e.x, this.y = e.y, this.z = e.z, this;
  }
  add(e) {
    return this.x += e.x, this.y += e.y, this.z += e.z, this;
  }
  addScalar(e) {
    return this.x += e, this.y += e, this.z += e, this;
  }
  addVectors(e, t) {
    return this.x = e.x + t.x, this.y = e.y + t.y, this.z = e.z + t.z, this;
  }
  addScaledVector(e, t) {
    return this.x += e.x * t, this.y += e.y * t, this.z += e.z * t, this;
  }
  sub(e) {
    return this.x -= e.x, this.y -= e.y, this.z -= e.z, this;
  }
  subScalar(e) {
    return this.x -= e, this.y -= e, this.z -= e, this;
  }
  subVectors(e, t) {
    return this.x = e.x - t.x, this.y = e.y - t.y, this.z = e.z - t.z, this;
  }
  multiply(e) {
    return this.x *= e.x, this.y *= e.y, this.z *= e.z, this;
  }
  multiplyScalar(e) {
    return this.x *= e, this.y *= e, this.z *= e, this;
  }
  multiplyVectors(e, t) {
    return this.x = e.x * t.x, this.y = e.y * t.y, this.z = e.z * t.z, this;
  }
  applyEuler(e) {
    return this.applyQuaternion(bs.setFromEuler(e));
  }
  applyAxisAngle(e, t) {
    return this.applyQuaternion(bs.setFromAxisAngle(e, t));
  }
  applyMatrix3(e) {
    const t = this.x, r = this.y, n = this.z, i = e.elements;
    return this.x = i[0] * t + i[3] * r + i[6] * n, this.y = i[1] * t + i[4] * r + i[7] * n, this.z = i[2] * t + i[5] * r + i[8] * n, this;
  }
  applyNormalMatrix(e) {
    return this.applyMatrix3(e).normalize();
  }
  applyMatrix4(e) {
    const t = this.x, r = this.y, n = this.z, i = e.elements, s = 1 / (i[3] * t + i[7] * r + i[11] * n + i[15]);
    return this.x = (i[0] * t + i[4] * r + i[8] * n + i[12]) * s, this.y = (i[1] * t + i[5] * r + i[9] * n + i[13]) * s, this.z = (i[2] * t + i[6] * r + i[10] * n + i[14]) * s, this;
  }
  applyQuaternion(e) {
    const t = this.x, r = this.y, n = this.z, i = e.x, s = e.y, o = e.z, l = e.w, c = 2 * (s * n - o * r), u = 2 * (o * t - i * n), f = 2 * (i * r - s * t);
    return this.x = t + l * c + s * f - o * u, this.y = r + l * u + o * c - i * f, this.z = n + l * f + i * u - s * c, this;
  }
  project(e) {
    return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix);
  }
  unproject(e) {
    return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld);
  }
  transformDirection(e) {
    const t = this.x, r = this.y, n = this.z, i = e.elements;
    return this.x = i[0] * t + i[4] * r + i[8] * n, this.y = i[1] * t + i[5] * r + i[9] * n, this.z = i[2] * t + i[6] * r + i[10] * n, this.normalize();
  }
  divide(e) {
    return this.x /= e.x, this.y /= e.y, this.z /= e.z, this;
  }
  divideScalar(e) {
    return this.multiplyScalar(1 / e);
  }
  min(e) {
    return this.x = Math.min(this.x, e.x), this.y = Math.min(this.y, e.y), this.z = Math.min(this.z, e.z), this;
  }
  max(e) {
    return this.x = Math.max(this.x, e.x), this.y = Math.max(this.y, e.y), this.z = Math.max(this.z, e.z), this;
  }
  clamp(e, t) {
    return this.x = Math.max(e.x, Math.min(t.x, this.x)), this.y = Math.max(e.y, Math.min(t.y, this.y)), this.z = Math.max(e.z, Math.min(t.z, this.z)), this;
  }
  clampScalar(e, t) {
    return this.x = Math.max(e, Math.min(t, this.x)), this.y = Math.max(e, Math.min(t, this.y)), this.z = Math.max(e, Math.min(t, this.z)), this;
  }
  clampLength(e, t) {
    const r = this.length();
    return this.divideScalar(r || 1).multiplyScalar(Math.max(e, Math.min(t, r)));
  }
  floor() {
    return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this.z = Math.floor(this.z), this;
  }
  ceil() {
    return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this.z = Math.ceil(this.z), this;
  }
  round() {
    return this.x = Math.round(this.x), this.y = Math.round(this.y), this.z = Math.round(this.z), this;
  }
  roundToZero() {
    return this.x = Math.trunc(this.x), this.y = Math.trunc(this.y), this.z = Math.trunc(this.z), this;
  }
  negate() {
    return this.x = -this.x, this.y = -this.y, this.z = -this.z, this;
  }
  dot(e) {
    return this.x * e.x + this.y * e.y + this.z * e.z;
  }
  // TODO lengthSquared?
  lengthSq() {
    return this.x * this.x + this.y * this.y + this.z * this.z;
  }
  length() {
    return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  }
  manhattanLength() {
    return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  }
  normalize() {
    return this.divideScalar(this.length() || 1);
  }
  setLength(e) {
    return this.normalize().multiplyScalar(e);
  }
  lerp(e, t) {
    return this.x += (e.x - this.x) * t, this.y += (e.y - this.y) * t, this.z += (e.z - this.z) * t, this;
  }
  lerpVectors(e, t, r) {
    return this.x = e.x + (t.x - e.x) * r, this.y = e.y + (t.y - e.y) * r, this.z = e.z + (t.z - e.z) * r, this;
  }
  cross(e) {
    return this.crossVectors(this, e);
  }
  crossVectors(e, t) {
    const r = e.x, n = e.y, i = e.z, s = t.x, o = t.y, l = t.z;
    return this.x = n * l - i * o, this.y = i * s - r * l, this.z = r * o - n * s, this;
  }
  projectOnVector(e) {
    const t = e.lengthSq();
    if (t === 0) return this.set(0, 0, 0);
    const r = e.dot(this) / t;
    return this.copy(e).multiplyScalar(r);
  }
  projectOnPlane(e) {
    return sa.copy(this).projectOnVector(e), this.sub(sa);
  }
  reflect(e) {
    return this.sub(sa.copy(e).multiplyScalar(2 * this.dot(e)));
  }
  angleTo(e) {
    const t = Math.sqrt(this.lengthSq() * e.lengthSq());
    if (t === 0) return Math.PI / 2;
    const r = this.dot(e) / t;
    return Math.acos(bt(r, -1, 1));
  }
  distanceTo(e) {
    return Math.sqrt(this.distanceToSquared(e));
  }
  distanceToSquared(e) {
    const t = this.x - e.x, r = this.y - e.y, n = this.z - e.z;
    return t * t + r * r + n * n;
  }
  manhattanDistanceTo(e) {
    return Math.abs(this.x - e.x) + Math.abs(this.y - e.y) + Math.abs(this.z - e.z);
  }
  setFromSpherical(e) {
    return this.setFromSphericalCoords(e.radius, e.phi, e.theta);
  }
  setFromSphericalCoords(e, t, r) {
    const n = Math.sin(t) * e;
    return this.x = n * Math.sin(r), this.y = Math.cos(t) * e, this.z = n * Math.cos(r), this;
  }
  setFromCylindrical(e) {
    return this.setFromCylindricalCoords(e.radius, e.theta, e.y);
  }
  setFromCylindricalCoords(e, t, r) {
    return this.x = e * Math.sin(t), this.y = r, this.z = e * Math.cos(t), this;
  }
  setFromMatrixPosition(e) {
    const t = e.elements;
    return this.x = t[12], this.y = t[13], this.z = t[14], this;
  }
  setFromMatrixScale(e) {
    const t = this.setFromMatrixColumn(e, 0).length(), r = this.setFromMatrixColumn(e, 1).length(), n = this.setFromMatrixColumn(e, 2).length();
    return this.x = t, this.y = r, this.z = n, this;
  }
  setFromMatrixColumn(e, t) {
    return this.fromArray(e.elements, t * 4);
  }
  setFromMatrix3Column(e, t) {
    return this.fromArray(e.elements, t * 3);
  }
  setFromEuler(e) {
    return this.x = e._x, this.y = e._y, this.z = e._z, this;
  }
  setFromColor(e) {
    return this.x = e.r, this.y = e.g, this.z = e.b, this;
  }
  equals(e) {
    return e.x === this.x && e.y === this.y && e.z === this.z;
  }
  fromArray(e, t = 0) {
    return this.x = e[t], this.y = e[t + 1], this.z = e[t + 2], this;
  }
  toArray(e = [], t = 0) {
    return e[t] = this.x, e[t + 1] = this.y, e[t + 2] = this.z, e;
  }
  fromBufferAttribute(e, t) {
    return this.x = e.getX(t), this.y = e.getY(t), this.z = e.getZ(t), this;
  }
  random() {
    return this.x = Math.random(), this.y = Math.random(), this.z = Math.random(), this;
  }
  randomDirection() {
    const e = Math.random() * Math.PI * 2, t = Math.random() * 2 - 1, r = Math.sqrt(1 - t * t);
    return this.x = r * Math.cos(e), this.y = t, this.z = r * Math.sin(e), this;
  }
  *[Symbol.iterator]() {
    yield this.x, yield this.y, yield this.z;
  }
}
const sa = /* @__PURE__ */ new j(), bs = /* @__PURE__ */ new qi();
class An {
  constructor(e = new j(1 / 0, 1 / 0, 1 / 0), t = new j(-1 / 0, -1 / 0, -1 / 0)) {
    this.isBox3 = !0, this.min = e, this.max = t;
  }
  set(e, t) {
    return this.min.copy(e), this.max.copy(t), this;
  }
  setFromArray(e) {
    this.makeEmpty();
    for (let t = 0, r = e.length; t < r; t += 3)
      this.expandByPoint(Zt.fromArray(e, t));
    return this;
  }
  setFromBufferAttribute(e) {
    this.makeEmpty();
    for (let t = 0, r = e.count; t < r; t++)
      this.expandByPoint(Zt.fromBufferAttribute(e, t));
    return this;
  }
  setFromPoints(e) {
    this.makeEmpty();
    for (let t = 0, r = e.length; t < r; t++)
      this.expandByPoint(e[t]);
    return this;
  }
  setFromCenterAndSize(e, t) {
    const r = Zt.copy(t).multiplyScalar(0.5);
    return this.min.copy(e).sub(r), this.max.copy(e).add(r), this;
  }
  setFromObject(e, t = !1) {
    return this.makeEmpty(), this.expandByObject(e, t);
  }
  clone() {
    return new this.constructor().copy(this);
  }
  copy(e) {
    return this.min.copy(e.min), this.max.copy(e.max), this;
  }
  makeEmpty() {
    return this.min.x = this.min.y = this.min.z = 1 / 0, this.max.x = this.max.y = this.max.z = -1 / 0, this;
  }
  isEmpty() {
    return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  }
  getCenter(e) {
    return this.isEmpty() ? e.set(0, 0, 0) : e.addVectors(this.min, this.max).multiplyScalar(0.5);
  }
  getSize(e) {
    return this.isEmpty() ? e.set(0, 0, 0) : e.subVectors(this.max, this.min);
  }
  expandByPoint(e) {
    return this.min.min(e), this.max.max(e), this;
  }
  expandByVector(e) {
    return this.min.sub(e), this.max.add(e), this;
  }
  expandByScalar(e) {
    return this.min.addScalar(-e), this.max.addScalar(e), this;
  }
  expandByObject(e, t = !1) {
    e.updateWorldMatrix(!1, !1);
    const r = e.geometry;
    if (r !== void 0) {
      const i = r.getAttribute("position");
      if (t === !0 && i !== void 0 && e.isInstancedMesh !== !0)
        for (let s = 0, o = i.count; s < o; s++)
          e.isMesh === !0 ? e.getVertexPosition(s, Zt) : Zt.fromBufferAttribute(i, s), Zt.applyMatrix4(e.matrixWorld), this.expandByPoint(Zt);
      else
        e.boundingBox !== void 0 ? (e.boundingBox === null && e.computeBoundingBox(), tr.copy(e.boundingBox)) : (r.boundingBox === null && r.computeBoundingBox(), tr.copy(r.boundingBox)), tr.applyMatrix4(e.matrixWorld), this.union(tr);
    }
    const n = e.children;
    for (let i = 0, s = n.length; i < s; i++)
      this.expandByObject(n[i], t);
    return this;
  }
  containsPoint(e) {
    return e.x >= this.min.x && e.x <= this.max.x && e.y >= this.min.y && e.y <= this.max.y && e.z >= this.min.z && e.z <= this.max.z;
  }
  containsBox(e) {
    return this.min.x <= e.min.x && e.max.x <= this.max.x && this.min.y <= e.min.y && e.max.y <= this.max.y && this.min.z <= e.min.z && e.max.z <= this.max.z;
  }
  getParameter(e, t) {
    return t.set(
      (e.x - this.min.x) / (this.max.x - this.min.x),
      (e.y - this.min.y) / (this.max.y - this.min.y),
      (e.z - this.min.z) / (this.max.z - this.min.z)
    );
  }
  intersectsBox(e) {
    return e.max.x >= this.min.x && e.min.x <= this.max.x && e.max.y >= this.min.y && e.min.y <= this.max.y && e.max.z >= this.min.z && e.min.z <= this.max.z;
  }
  intersectsSphere(e) {
    return this.clampPoint(e.center, Zt), Zt.distanceToSquared(e.center) <= e.radius * e.radius;
  }
  intersectsPlane(e) {
    let t, r;
    return e.normal.x > 0 ? (t = e.normal.x * this.min.x, r = e.normal.x * this.max.x) : (t = e.normal.x * this.max.x, r = e.normal.x * this.min.x), e.normal.y > 0 ? (t += e.normal.y * this.min.y, r += e.normal.y * this.max.y) : (t += e.normal.y * this.max.y, r += e.normal.y * this.min.y), e.normal.z > 0 ? (t += e.normal.z * this.min.z, r += e.normal.z * this.max.z) : (t += e.normal.z * this.max.z, r += e.normal.z * this.min.z), t <= -e.constant && r >= -e.constant;
  }
  intersectsTriangle(e) {
    if (this.isEmpty())
      return !1;
    this.getCenter(Pi), nr.subVectors(this.max, Pi), Yn.subVectors(e.a, Pi), jn.subVectors(e.b, Pi), Zn.subVectors(e.c, Pi), _n.subVectors(jn, Yn), xn.subVectors(Zn, jn), wn.subVectors(Yn, Zn);
    let t = [
      0,
      -_n.z,
      _n.y,
      0,
      -xn.z,
      xn.y,
      0,
      -wn.z,
      wn.y,
      _n.z,
      0,
      -_n.x,
      xn.z,
      0,
      -xn.x,
      wn.z,
      0,
      -wn.x,
      -_n.y,
      _n.x,
      0,
      -xn.y,
      xn.x,
      0,
      -wn.y,
      wn.x,
      0
    ];
    return !oa(t, Yn, jn, Zn, nr) || (t = [1, 0, 0, 0, 1, 0, 0, 0, 1], !oa(t, Yn, jn, Zn, nr)) ? !1 : (ir.crossVectors(_n, xn), t = [ir.x, ir.y, ir.z], oa(t, Yn, jn, Zn, nr));
  }
  clampPoint(e, t) {
    return t.copy(e).clamp(this.min, this.max);
  }
  distanceToPoint(e) {
    return this.clampPoint(e, Zt).distanceTo(e);
  }
  getBoundingSphere(e) {
    return this.isEmpty() ? e.makeEmpty() : (this.getCenter(e.center), e.radius = this.getSize(Zt).length() * 0.5), e;
  }
  intersect(e) {
    return this.min.max(e.min), this.max.min(e.max), this.isEmpty() && this.makeEmpty(), this;
  }
  union(e) {
    return this.min.min(e.min), this.max.max(e.max), this;
  }
  applyMatrix4(e) {
    return this.isEmpty() ? this : (ln[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(e), ln[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(e), ln[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(e), ln[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(e), ln[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(e), ln[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(e), ln[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(e), ln[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(e), this.setFromPoints(ln), this);
  }
  translate(e) {
    return this.min.add(e), this.max.add(e), this;
  }
  equals(e) {
    return e.min.equals(this.min) && e.max.equals(this.max);
  }
}
const ln = [
  /* @__PURE__ */ new j(),
  /* @__PURE__ */ new j(),
  /* @__PURE__ */ new j(),
  /* @__PURE__ */ new j(),
  /* @__PURE__ */ new j(),
  /* @__PURE__ */ new j(),
  /* @__PURE__ */ new j(),
  /* @__PURE__ */ new j()
], Zt = /* @__PURE__ */ new j(), tr = /* @__PURE__ */ new An(), Yn = /* @__PURE__ */ new j(), jn = /* @__PURE__ */ new j(), Zn = /* @__PURE__ */ new j(), _n = /* @__PURE__ */ new j(), xn = /* @__PURE__ */ new j(), wn = /* @__PURE__ */ new j(), Pi = /* @__PURE__ */ new j(), nr = /* @__PURE__ */ new j(), ir = /* @__PURE__ */ new j(), Cn = /* @__PURE__ */ new j();
function oa(a, e, t, r, n) {
  for (let i = 0, s = a.length - 3; i <= s; i += 3) {
    Cn.fromArray(a, i);
    const o = n.x * Math.abs(Cn.x) + n.y * Math.abs(Cn.y) + n.z * Math.abs(Cn.z), l = e.dot(Cn), c = t.dot(Cn), u = r.dot(Cn);
    if (Math.max(-Math.max(l, c, u), Math.min(l, c, u)) > o)
      return !1;
  }
  return !0;
}
const Fl = /* @__PURE__ */ new An(), Ui = /* @__PURE__ */ new j(), la = /* @__PURE__ */ new j();
class gi {
  constructor(e = new j(), t = -1) {
    this.isSphere = !0, this.center = e, this.radius = t;
  }
  set(e, t) {
    return this.center.copy(e), this.radius = t, this;
  }
  setFromPoints(e, t) {
    const r = this.center;
    t !== void 0 ? r.copy(t) : Fl.setFromPoints(e).getCenter(r);
    let n = 0;
    for (let i = 0, s = e.length; i < s; i++)
      n = Math.max(n, r.distanceToSquared(e[i]));
    return this.radius = Math.sqrt(n), this;
  }
  copy(e) {
    return this.center.copy(e.center), this.radius = e.radius, this;
  }
  isEmpty() {
    return this.radius < 0;
  }
  makeEmpty() {
    return this.center.set(0, 0, 0), this.radius = -1, this;
  }
  containsPoint(e) {
    return e.distanceToSquared(this.center) <= this.radius * this.radius;
  }
  distanceToPoint(e) {
    return e.distanceTo(this.center) - this.radius;
  }
  intersectsSphere(e) {
    const t = this.radius + e.radius;
    return e.center.distanceToSquared(this.center) <= t * t;
  }
  intersectsBox(e) {
    return e.intersectsSphere(this);
  }
  intersectsPlane(e) {
    return Math.abs(e.distanceToPoint(this.center)) <= this.radius;
  }
  clampPoint(e, t) {
    const r = this.center.distanceToSquared(e);
    return t.copy(e), r > this.radius * this.radius && (t.sub(this.center).normalize(), t.multiplyScalar(this.radius).add(this.center)), t;
  }
  getBoundingBox(e) {
    return this.isEmpty() ? (e.makeEmpty(), e) : (e.set(this.center, this.center), e.expandByScalar(this.radius), e);
  }
  applyMatrix4(e) {
    return this.center.applyMatrix4(e), this.radius = this.radius * e.getMaxScaleOnAxis(), this;
  }
  translate(e) {
    return this.center.add(e), this;
  }
  expandByPoint(e) {
    if (this.isEmpty())
      return this.center.copy(e), this.radius = 0, this;
    Ui.subVectors(e, this.center);
    const t = Ui.lengthSq();
    if (t > this.radius * this.radius) {
      const r = Math.sqrt(t), n = (r - this.radius) * 0.5;
      this.center.addScaledVector(Ui, n / r), this.radius += n;
    }
    return this;
  }
  union(e) {
    return e.isEmpty() ? this : this.isEmpty() ? (this.copy(e), this) : (this.center.equals(e.center) === !0 ? this.radius = Math.max(this.radius, e.radius) : (la.subVectors(e.center, this.center).setLength(e.radius), this.expandByPoint(Ui.copy(e.center).add(la)), this.expandByPoint(Ui.copy(e.center).sub(la))), this);
  }
  equals(e) {
    return e.center.equals(this.center) && e.radius === this.radius;
  }
  clone() {
    return new this.constructor().copy(this);
  }
}
const cn = /* @__PURE__ */ new j(), ca = /* @__PURE__ */ new j(), rr = /* @__PURE__ */ new j(), Sn = /* @__PURE__ */ new j(), ua = /* @__PURE__ */ new j(), ar = /* @__PURE__ */ new j(), ha = /* @__PURE__ */ new j();
class Ja {
  constructor(e = new j(), t = new j(0, 0, -1)) {
    this.origin = e, this.direction = t;
  }
  set(e, t) {
    return this.origin.copy(e), this.direction.copy(t), this;
  }
  copy(e) {
    return this.origin.copy(e.origin), this.direction.copy(e.direction), this;
  }
  at(e, t) {
    return t.copy(this.origin).addScaledVector(this.direction, e);
  }
  lookAt(e) {
    return this.direction.copy(e).sub(this.origin).normalize(), this;
  }
  recast(e) {
    return this.origin.copy(this.at(e, cn)), this;
  }
  closestPointToPoint(e, t) {
    t.subVectors(e, this.origin);
    const r = t.dot(this.direction);
    return r < 0 ? t.copy(this.origin) : t.copy(this.origin).addScaledVector(this.direction, r);
  }
  distanceToPoint(e) {
    return Math.sqrt(this.distanceSqToPoint(e));
  }
  distanceSqToPoint(e) {
    const t = cn.subVectors(e, this.origin).dot(this.direction);
    return t < 0 ? this.origin.distanceToSquared(e) : (cn.copy(this.origin).addScaledVector(this.direction, t), cn.distanceToSquared(e));
  }
  distanceSqToSegment(e, t, r, n) {
    ca.copy(e).add(t).multiplyScalar(0.5), rr.copy(t).sub(e).normalize(), Sn.copy(this.origin).sub(ca);
    const i = e.distanceTo(t) * 0.5, s = -this.direction.dot(rr), o = Sn.dot(this.direction), l = -Sn.dot(rr), c = Sn.lengthSq(), u = Math.abs(1 - s * s);
    let f, h, d, g;
    if (u > 0)
      if (f = s * l - o, h = s * o - l, g = i * u, f >= 0)
        if (h >= -g)
          if (h <= g) {
            const v = 1 / u;
            f *= v, h *= v, d = f * (f + s * h + 2 * o) + h * (s * f + h + 2 * l) + c;
          } else
            h = i, f = Math.max(0, -(s * h + o)), d = -f * f + h * (h + 2 * l) + c;
        else
          h = -i, f = Math.max(0, -(s * h + o)), d = -f * f + h * (h + 2 * l) + c;
      else
        h <= -g ? (f = Math.max(0, -(-s * i + o)), h = f > 0 ? -i : Math.min(Math.max(-i, -l), i), d = -f * f + h * (h + 2 * l) + c) : h <= g ? (f = 0, h = Math.min(Math.max(-i, -l), i), d = h * (h + 2 * l) + c) : (f = Math.max(0, -(s * i + o)), h = f > 0 ? i : Math.min(Math.max(-i, -l), i), d = -f * f + h * (h + 2 * l) + c);
    else
      h = s > 0 ? -i : i, f = Math.max(0, -(s * h + o)), d = -f * f + h * (h + 2 * l) + c;
    return r && r.copy(this.origin).addScaledVector(this.direction, f), n && n.copy(ca).addScaledVector(rr, h), d;
  }
  intersectSphere(e, t) {
    cn.subVectors(e.center, this.origin);
    const r = cn.dot(this.direction), n = cn.dot(cn) - r * r, i = e.radius * e.radius;
    if (n > i) return null;
    const s = Math.sqrt(i - n), o = r - s, l = r + s;
    return l < 0 ? null : o < 0 ? this.at(l, t) : this.at(o, t);
  }
  intersectsSphere(e) {
    return this.distanceSqToPoint(e.center) <= e.radius * e.radius;
  }
  distanceToPlane(e) {
    const t = e.normal.dot(this.direction);
    if (t === 0)
      return e.distanceToPoint(this.origin) === 0 ? 0 : null;
    const r = -(this.origin.dot(e.normal) + e.constant) / t;
    return r >= 0 ? r : null;
  }
  intersectPlane(e, t) {
    const r = this.distanceToPlane(e);
    return r === null ? null : this.at(r, t);
  }
  intersectsPlane(e) {
    const t = e.distanceToPoint(this.origin);
    return t === 0 || e.normal.dot(this.direction) * t < 0;
  }
  intersectBox(e, t) {
    let r, n, i, s, o, l;
    const c = 1 / this.direction.x, u = 1 / this.direction.y, f = 1 / this.direction.z, h = this.origin;
    return c >= 0 ? (r = (e.min.x - h.x) * c, n = (e.max.x - h.x) * c) : (r = (e.max.x - h.x) * c, n = (e.min.x - h.x) * c), u >= 0 ? (i = (e.min.y - h.y) * u, s = (e.max.y - h.y) * u) : (i = (e.max.y - h.y) * u, s = (e.min.y - h.y) * u), r > s || i > n || ((i > r || isNaN(r)) && (r = i), (s < n || isNaN(n)) && (n = s), f >= 0 ? (o = (e.min.z - h.z) * f, l = (e.max.z - h.z) * f) : (o = (e.max.z - h.z) * f, l = (e.min.z - h.z) * f), r > l || o > n) || ((o > r || r !== r) && (r = o), (l < n || n !== n) && (n = l), n < 0) ? null : this.at(r >= 0 ? r : n, t);
  }
  intersectsBox(e) {
    return this.intersectBox(e, cn) !== null;
  }
  intersectTriangle(e, t, r, n, i) {
    ua.subVectors(t, e), ar.subVectors(r, e), ha.crossVectors(ua, ar);
    let s = this.direction.dot(ha), o;
    if (s > 0) {
      if (n) return null;
      o = 1;
    } else if (s < 0)
      o = -1, s = -s;
    else
      return null;
    Sn.subVectors(this.origin, e);
    const l = o * this.direction.dot(ar.crossVectors(Sn, ar));
    if (l < 0)
      return null;
    const c = o * this.direction.dot(ua.cross(Sn));
    if (c < 0 || l + c > s)
      return null;
    const u = -o * Sn.dot(ha);
    return u < 0 ? null : this.at(u / s, i);
  }
  applyMatrix4(e) {
    return this.origin.applyMatrix4(e), this.direction.transformDirection(e), this;
  }
  equals(e) {
    return e.origin.equals(this.origin) && e.direction.equals(this.direction);
  }
  clone() {
    return new this.constructor().copy(this);
  }
}
class st {
  constructor(e, t, r, n, i, s, o, l, c, u, f, h, d, g, v, m) {
    st.prototype.isMatrix4 = !0, this.elements = [
      1,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      1
    ], e !== void 0 && this.set(e, t, r, n, i, s, o, l, c, u, f, h, d, g, v, m);
  }
  set(e, t, r, n, i, s, o, l, c, u, f, h, d, g, v, m) {
    const p = this.elements;
    return p[0] = e, p[4] = t, p[8] = r, p[12] = n, p[1] = i, p[5] = s, p[9] = o, p[13] = l, p[2] = c, p[6] = u, p[10] = f, p[14] = h, p[3] = d, p[7] = g, p[11] = v, p[15] = m, this;
  }
  identity() {
    return this.set(
      1,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  clone() {
    return new st().fromArray(this.elements);
  }
  copy(e) {
    const t = this.elements, r = e.elements;
    return t[0] = r[0], t[1] = r[1], t[2] = r[2], t[3] = r[3], t[4] = r[4], t[5] = r[5], t[6] = r[6], t[7] = r[7], t[8] = r[8], t[9] = r[9], t[10] = r[10], t[11] = r[11], t[12] = r[12], t[13] = r[13], t[14] = r[14], t[15] = r[15], this;
  }
  copyPosition(e) {
    const t = this.elements, r = e.elements;
    return t[12] = r[12], t[13] = r[13], t[14] = r[14], this;
  }
  setFromMatrix3(e) {
    const t = e.elements;
    return this.set(
      t[0],
      t[3],
      t[6],
      0,
      t[1],
      t[4],
      t[7],
      0,
      t[2],
      t[5],
      t[8],
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  extractBasis(e, t, r) {
    return e.setFromMatrixColumn(this, 0), t.setFromMatrixColumn(this, 1), r.setFromMatrixColumn(this, 2), this;
  }
  makeBasis(e, t, r) {
    return this.set(
      e.x,
      t.x,
      r.x,
      0,
      e.y,
      t.y,
      r.y,
      0,
      e.z,
      t.z,
      r.z,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  extractRotation(e) {
    const t = this.elements, r = e.elements, n = 1 / Kn.setFromMatrixColumn(e, 0).length(), i = 1 / Kn.setFromMatrixColumn(e, 1).length(), s = 1 / Kn.setFromMatrixColumn(e, 2).length();
    return t[0] = r[0] * n, t[1] = r[1] * n, t[2] = r[2] * n, t[3] = 0, t[4] = r[4] * i, t[5] = r[5] * i, t[6] = r[6] * i, t[7] = 0, t[8] = r[8] * s, t[9] = r[9] * s, t[10] = r[10] * s, t[11] = 0, t[12] = 0, t[13] = 0, t[14] = 0, t[15] = 1, this;
  }
  makeRotationFromEuler(e) {
    const t = this.elements, r = e.x, n = e.y, i = e.z, s = Math.cos(r), o = Math.sin(r), l = Math.cos(n), c = Math.sin(n), u = Math.cos(i), f = Math.sin(i);
    if (e.order === "XYZ") {
      const h = s * u, d = s * f, g = o * u, v = o * f;
      t[0] = l * u, t[4] = -l * f, t[8] = c, t[1] = d + g * c, t[5] = h - v * c, t[9] = -o * l, t[2] = v - h * c, t[6] = g + d * c, t[10] = s * l;
    } else if (e.order === "YXZ") {
      const h = l * u, d = l * f, g = c * u, v = c * f;
      t[0] = h + v * o, t[4] = g * o - d, t[8] = s * c, t[1] = s * f, t[5] = s * u, t[9] = -o, t[2] = d * o - g, t[6] = v + h * o, t[10] = s * l;
    } else if (e.order === "ZXY") {
      const h = l * u, d = l * f, g = c * u, v = c * f;
      t[0] = h - v * o, t[4] = -s * f, t[8] = g + d * o, t[1] = d + g * o, t[5] = s * u, t[9] = v - h * o, t[2] = -s * c, t[6] = o, t[10] = s * l;
    } else if (e.order === "ZYX") {
      const h = s * u, d = s * f, g = o * u, v = o * f;
      t[0] = l * u, t[4] = g * c - d, t[8] = h * c + v, t[1] = l * f, t[5] = v * c + h, t[9] = d * c - g, t[2] = -c, t[6] = o * l, t[10] = s * l;
    } else if (e.order === "YZX") {
      const h = s * l, d = s * c, g = o * l, v = o * c;
      t[0] = l * u, t[4] = v - h * f, t[8] = g * f + d, t[1] = f, t[5] = s * u, t[9] = -o * u, t[2] = -c * u, t[6] = d * f + g, t[10] = h - v * f;
    } else if (e.order === "XZY") {
      const h = s * l, d = s * c, g = o * l, v = o * c;
      t[0] = l * u, t[4] = -f, t[8] = c * u, t[1] = h * f + v, t[5] = s * u, t[9] = d * f - g, t[2] = g * f - d, t[6] = o * u, t[10] = v * f + h;
    }
    return t[3] = 0, t[7] = 0, t[11] = 0, t[12] = 0, t[13] = 0, t[14] = 0, t[15] = 1, this;
  }
  makeRotationFromQuaternion(e) {
    return this.compose(Il, e, Nl);
  }
  lookAt(e, t, r) {
    const n = this.elements;
    return zt.subVectors(e, t), zt.lengthSq() === 0 && (zt.z = 1), zt.normalize(), yn.crossVectors(r, zt), yn.lengthSq() === 0 && (Math.abs(r.z) === 1 ? zt.x += 1e-4 : zt.z += 1e-4, zt.normalize(), yn.crossVectors(r, zt)), yn.normalize(), sr.crossVectors(zt, yn), n[0] = yn.x, n[4] = sr.x, n[8] = zt.x, n[1] = yn.y, n[5] = sr.y, n[9] = zt.y, n[2] = yn.z, n[6] = sr.z, n[10] = zt.z, this;
  }
  multiply(e) {
    return this.multiplyMatrices(this, e);
  }
  premultiply(e) {
    return this.multiplyMatrices(e, this);
  }
  multiplyMatrices(e, t) {
    const r = e.elements, n = t.elements, i = this.elements, s = r[0], o = r[4], l = r[8], c = r[12], u = r[1], f = r[5], h = r[9], d = r[13], g = r[2], v = r[6], m = r[10], p = r[14], T = r[3], x = r[7], _ = r[11], D = r[15], C = n[0], A = n[4], R = n[8], E = n[12], S = n[1], F = n[5], L = n[9], B = n[13], k = n[2], O = n[6], z = n[10], ne = n[14], q = n[3], K = n[7], Z = n[11], N = n[15];
    return i[0] = s * C + o * S + l * k + c * q, i[4] = s * A + o * F + l * O + c * K, i[8] = s * R + o * L + l * z + c * Z, i[12] = s * E + o * B + l * ne + c * N, i[1] = u * C + f * S + h * k + d * q, i[5] = u * A + f * F + h * O + d * K, i[9] = u * R + f * L + h * z + d * Z, i[13] = u * E + f * B + h * ne + d * N, i[2] = g * C + v * S + m * k + p * q, i[6] = g * A + v * F + m * O + p * K, i[10] = g * R + v * L + m * z + p * Z, i[14] = g * E + v * B + m * ne + p * N, i[3] = T * C + x * S + _ * k + D * q, i[7] = T * A + x * F + _ * O + D * K, i[11] = T * R + x * L + _ * z + D * Z, i[15] = T * E + x * B + _ * ne + D * N, this;
  }
  multiplyScalar(e) {
    const t = this.elements;
    return t[0] *= e, t[4] *= e, t[8] *= e, t[12] *= e, t[1] *= e, t[5] *= e, t[9] *= e, t[13] *= e, t[2] *= e, t[6] *= e, t[10] *= e, t[14] *= e, t[3] *= e, t[7] *= e, t[11] *= e, t[15] *= e, this;
  }
  determinant() {
    const e = this.elements, t = e[0], r = e[4], n = e[8], i = e[12], s = e[1], o = e[5], l = e[9], c = e[13], u = e[2], f = e[6], h = e[10], d = e[14], g = e[3], v = e[7], m = e[11], p = e[15];
    return g * (+i * l * f - n * c * f - i * o * h + r * c * h + n * o * d - r * l * d) + v * (+t * l * d - t * c * h + i * s * h - n * s * d + n * c * u - i * l * u) + m * (+t * c * f - t * o * d - i * s * f + r * s * d + i * o * u - r * c * u) + p * (-n * o * u - t * l * f + t * o * h + n * s * f - r * s * h + r * l * u);
  }
  transpose() {
    const e = this.elements;
    let t;
    return t = e[1], e[1] = e[4], e[4] = t, t = e[2], e[2] = e[8], e[8] = t, t = e[6], e[6] = e[9], e[9] = t, t = e[3], e[3] = e[12], e[12] = t, t = e[7], e[7] = e[13], e[13] = t, t = e[11], e[11] = e[14], e[14] = t, this;
  }
  setPosition(e, t, r) {
    const n = this.elements;
    return e.isVector3 ? (n[12] = e.x, n[13] = e.y, n[14] = e.z) : (n[12] = e, n[13] = t, n[14] = r), this;
  }
  invert() {
    const e = this.elements, t = e[0], r = e[1], n = e[2], i = e[3], s = e[4], o = e[5], l = e[6], c = e[7], u = e[8], f = e[9], h = e[10], d = e[11], g = e[12], v = e[13], m = e[14], p = e[15], T = f * m * c - v * h * c + v * l * d - o * m * d - f * l * p + o * h * p, x = g * h * c - u * m * c - g * l * d + s * m * d + u * l * p - s * h * p, _ = u * v * c - g * f * c + g * o * d - s * v * d - u * o * p + s * f * p, D = g * f * l - u * v * l - g * o * h + s * v * h + u * o * m - s * f * m, C = t * T + r * x + n * _ + i * D;
    if (C === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    const A = 1 / C;
    return e[0] = T * A, e[1] = (v * h * i - f * m * i - v * n * d + r * m * d + f * n * p - r * h * p) * A, e[2] = (o * m * i - v * l * i + v * n * c - r * m * c - o * n * p + r * l * p) * A, e[3] = (f * l * i - o * h * i - f * n * c + r * h * c + o * n * d - r * l * d) * A, e[4] = x * A, e[5] = (u * m * i - g * h * i + g * n * d - t * m * d - u * n * p + t * h * p) * A, e[6] = (g * l * i - s * m * i - g * n * c + t * m * c + s * n * p - t * l * p) * A, e[7] = (s * h * i - u * l * i + u * n * c - t * h * c - s * n * d + t * l * d) * A, e[8] = _ * A, e[9] = (g * f * i - u * v * i - g * r * d + t * v * d + u * r * p - t * f * p) * A, e[10] = (s * v * i - g * o * i + g * r * c - t * v * c - s * r * p + t * o * p) * A, e[11] = (u * o * i - s * f * i - u * r * c + t * f * c + s * r * d - t * o * d) * A, e[12] = D * A, e[13] = (u * v * n - g * f * n + g * r * h - t * v * h - u * r * m + t * f * m) * A, e[14] = (g * o * n - s * v * n - g * r * l + t * v * l + s * r * m - t * o * m) * A, e[15] = (s * f * n - u * o * n + u * r * l - t * f * l - s * r * h + t * o * h) * A, this;
  }
  scale(e) {
    const t = this.elements, r = e.x, n = e.y, i = e.z;
    return t[0] *= r, t[4] *= n, t[8] *= i, t[1] *= r, t[5] *= n, t[9] *= i, t[2] *= r, t[6] *= n, t[10] *= i, t[3] *= r, t[7] *= n, t[11] *= i, this;
  }
  getMaxScaleOnAxis() {
    const e = this.elements, t = e[0] * e[0] + e[1] * e[1] + e[2] * e[2], r = e[4] * e[4] + e[5] * e[5] + e[6] * e[6], n = e[8] * e[8] + e[9] * e[9] + e[10] * e[10];
    return Math.sqrt(Math.max(t, r, n));
  }
  makeTranslation(e, t, r) {
    return e.isVector3 ? this.set(
      1,
      0,
      0,
      e.x,
      0,
      1,
      0,
      e.y,
      0,
      0,
      1,
      e.z,
      0,
      0,
      0,
      1
    ) : this.set(
      1,
      0,
      0,
      e,
      0,
      1,
      0,
      t,
      0,
      0,
      1,
      r,
      0,
      0,
      0,
      1
    ), this;
  }
  makeRotationX(e) {
    const t = Math.cos(e), r = Math.sin(e);
    return this.set(
      1,
      0,
      0,
      0,
      0,
      t,
      -r,
      0,
      0,
      r,
      t,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  makeRotationY(e) {
    const t = Math.cos(e), r = Math.sin(e);
    return this.set(
      t,
      0,
      r,
      0,
      0,
      1,
      0,
      0,
      -r,
      0,
      t,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  makeRotationZ(e) {
    const t = Math.cos(e), r = Math.sin(e);
    return this.set(
      t,
      -r,
      0,
      0,
      r,
      t,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  makeRotationAxis(e, t) {
    const r = Math.cos(t), n = Math.sin(t), i = 1 - r, s = e.x, o = e.y, l = e.z, c = i * s, u = i * o;
    return this.set(
      c * s + r,
      c * o - n * l,
      c * l + n * o,
      0,
      c * o + n * l,
      u * o + r,
      u * l - n * s,
      0,
      c * l - n * o,
      u * l + n * s,
      i * l * l + r,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  makeScale(e, t, r) {
    return this.set(
      e,
      0,
      0,
      0,
      0,
      t,
      0,
      0,
      0,
      0,
      r,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  makeShear(e, t, r, n, i, s) {
    return this.set(
      1,
      r,
      i,
      0,
      e,
      1,
      s,
      0,
      t,
      n,
      1,
      0,
      0,
      0,
      0,
      1
    ), this;
  }
  compose(e, t, r) {
    const n = this.elements, i = t._x, s = t._y, o = t._z, l = t._w, c = i + i, u = s + s, f = o + o, h = i * c, d = i * u, g = i * f, v = s * u, m = s * f, p = o * f, T = l * c, x = l * u, _ = l * f, D = r.x, C = r.y, A = r.z;
    return n[0] = (1 - (v + p)) * D, n[1] = (d + _) * D, n[2] = (g - x) * D, n[3] = 0, n[4] = (d - _) * C, n[5] = (1 - (h + p)) * C, n[6] = (m + T) * C, n[7] = 0, n[8] = (g + x) * A, n[9] = (m - T) * A, n[10] = (1 - (h + v)) * A, n[11] = 0, n[12] = e.x, n[13] = e.y, n[14] = e.z, n[15] = 1, this;
  }
  decompose(e, t, r) {
    const n = this.elements;
    let i = Kn.set(n[0], n[1], n[2]).length();
    const s = Kn.set(n[4], n[5], n[6]).length(), o = Kn.set(n[8], n[9], n[10]).length();
    this.determinant() < 0 && (i = -i), e.x = n[12], e.y = n[13], e.z = n[14], Kt.copy(this);
    const c = 1 / i, u = 1 / s, f = 1 / o;
    return Kt.elements[0] *= c, Kt.elements[1] *= c, Kt.elements[2] *= c, Kt.elements[4] *= u, Kt.elements[5] *= u, Kt.elements[6] *= u, Kt.elements[8] *= f, Kt.elements[9] *= f, Kt.elements[10] *= f, t.setFromRotationMatrix(Kt), r.x = i, r.y = s, r.z = o, this;
  }
  makePerspective(e, t, r, n, i, s, o = 2e3) {
    const l = this.elements, c = 2 * i / (t - e), u = 2 * i / (r - n), f = (t + e) / (t - e), h = (r + n) / (r - n);
    let d, g;
    if (o === 2e3)
      d = -(s + i) / (s - i), g = -2 * s * i / (s - i);
    else if (o === 2001)
      d = -s / (s - i), g = -s * i / (s - i);
    else
      throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: " + o);
    return l[0] = c, l[4] = 0, l[8] = f, l[12] = 0, l[1] = 0, l[5] = u, l[9] = h, l[13] = 0, l[2] = 0, l[6] = 0, l[10] = d, l[14] = g, l[3] = 0, l[7] = 0, l[11] = -1, l[15] = 0, this;
  }
  makeOrthographic(e, t, r, n, i, s, o = 2e3) {
    const l = this.elements, c = 1 / (t - e), u = 1 / (r - n), f = 1 / (s - i), h = (t + e) * c, d = (r + n) * u;
    let g, v;
    if (o === 2e3)
      g = (s + i) * f, v = -2 * f;
    else if (o === 2001)
      g = i * f, v = -1 * f;
    else
      throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: " + o);
    return l[0] = 2 * c, l[4] = 0, l[8] = 0, l[12] = -h, l[1] = 0, l[5] = 2 * u, l[9] = 0, l[13] = -d, l[2] = 0, l[6] = 0, l[10] = v, l[14] = -g, l[3] = 0, l[7] = 0, l[11] = 0, l[15] = 1, this;
  }
  equals(e) {
    const t = this.elements, r = e.elements;
    for (let n = 0; n < 16; n++)
      if (t[n] !== r[n]) return !1;
    return !0;
  }
  fromArray(e, t = 0) {
    for (let r = 0; r < 16; r++)
      this.elements[r] = e[r + t];
    return this;
  }
  toArray(e = [], t = 0) {
    const r = this.elements;
    return e[t] = r[0], e[t + 1] = r[1], e[t + 2] = r[2], e[t + 3] = r[3], e[t + 4] = r[4], e[t + 5] = r[5], e[t + 6] = r[6], e[t + 7] = r[7], e[t + 8] = r[8], e[t + 9] = r[9], e[t + 10] = r[10], e[t + 11] = r[11], e[t + 12] = r[12], e[t + 13] = r[13], e[t + 14] = r[14], e[t + 15] = r[15], e;
  }
}
const Kn = /* @__PURE__ */ new j(), Kt = /* @__PURE__ */ new st(), Il = /* @__PURE__ */ new j(0, 0, 0), Nl = /* @__PURE__ */ new j(1, 1, 1), yn = /* @__PURE__ */ new j(), sr = /* @__PURE__ */ new j(), zt = /* @__PURE__ */ new j(), As = /* @__PURE__ */ new st(), ws = /* @__PURE__ */ new qi();
class mn {
  constructor(e = 0, t = 0, r = 0, n = mn.DEFAULT_ORDER) {
    this.isEuler = !0, this._x = e, this._y = t, this._z = r, this._order = n;
  }
  get x() {
    return this._x;
  }
  set x(e) {
    this._x = e, this._onChangeCallback();
  }
  get y() {
    return this._y;
  }
  set y(e) {
    this._y = e, this._onChangeCallback();
  }
  get z() {
    return this._z;
  }
  set z(e) {
    this._z = e, this._onChangeCallback();
  }
  get order() {
    return this._order;
  }
  set order(e) {
    this._order = e, this._onChangeCallback();
  }
  set(e, t, r, n = this._order) {
    return this._x = e, this._y = t, this._z = r, this._order = n, this._onChangeCallback(), this;
  }
  clone() {
    return new this.constructor(this._x, this._y, this._z, this._order);
  }
  copy(e) {
    return this._x = e._x, this._y = e._y, this._z = e._z, this._order = e._order, this._onChangeCallback(), this;
  }
  setFromRotationMatrix(e, t = this._order, r = !0) {
    const n = e.elements, i = n[0], s = n[4], o = n[8], l = n[1], c = n[5], u = n[9], f = n[2], h = n[6], d = n[10];
    switch (t) {
      case "XYZ":
        this._y = Math.asin(bt(o, -1, 1)), Math.abs(o) < 0.9999999 ? (this._x = Math.atan2(-u, d), this._z = Math.atan2(-s, i)) : (this._x = Math.atan2(h, c), this._z = 0);
        break;
      case "YXZ":
        this._x = Math.asin(-bt(u, -1, 1)), Math.abs(u) < 0.9999999 ? (this._y = Math.atan2(o, d), this._z = Math.atan2(l, c)) : (this._y = Math.atan2(-f, i), this._z = 0);
        break;
      case "ZXY":
        this._x = Math.asin(bt(h, -1, 1)), Math.abs(h) < 0.9999999 ? (this._y = Math.atan2(-f, d), this._z = Math.atan2(-s, c)) : (this._y = 0, this._z = Math.atan2(l, i));
        break;
      case "ZYX":
        this._y = Math.asin(-bt(f, -1, 1)), Math.abs(f) < 0.9999999 ? (this._x = Math.atan2(h, d), this._z = Math.atan2(l, i)) : (this._x = 0, this._z = Math.atan2(-s, c));
        break;
      case "YZX":
        this._z = Math.asin(bt(l, -1, 1)), Math.abs(l) < 0.9999999 ? (this._x = Math.atan2(-u, c), this._y = Math.atan2(-f, i)) : (this._x = 0, this._y = Math.atan2(o, d));
        break;
      case "XZY":
        this._z = Math.asin(-bt(s, -1, 1)), Math.abs(s) < 0.9999999 ? (this._x = Math.atan2(h, c), this._y = Math.atan2(o, i)) : (this._x = Math.atan2(-u, d), this._y = 0);
        break;
      default:
        console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: " + t);
    }
    return this._order = t, r === !0 && this._onChangeCallback(), this;
  }
  setFromQuaternion(e, t, r) {
    return As.makeRotationFromQuaternion(e), this.setFromRotationMatrix(As, t, r);
  }
  setFromVector3(e, t = this._order) {
    return this.set(e.x, e.y, e.z, t);
  }
  reorder(e) {
    return ws.setFromEuler(this), this.setFromQuaternion(ws, e);
  }
  equals(e) {
    return e._x === this._x && e._y === this._y && e._z === this._z && e._order === this._order;
  }
  fromArray(e) {
    return this._x = e[0], this._y = e[1], this._z = e[2], e[3] !== void 0 && (this._order = e[3]), this._onChangeCallback(), this;
  }
  toArray(e = [], t = 0) {
    return e[t] = this._x, e[t + 1] = this._y, e[t + 2] = this._z, e[t + 3] = this._order, e;
  }
  _onChange(e) {
    return this._onChangeCallback = e, this;
  }
  _onChangeCallback() {
  }
  *[Symbol.iterator]() {
    yield this._x, yield this._y, yield this._z, yield this._order;
  }
}
mn.DEFAULT_ORDER = "XYZ";
class Bo {
  constructor() {
    this.mask = 1;
  }
  set(e) {
    this.mask = (1 << e | 0) >>> 0;
  }
  enable(e) {
    this.mask |= 1 << e | 0;
  }
  enableAll() {
    this.mask = -1;
  }
  toggle(e) {
    this.mask ^= 1 << e | 0;
  }
  disable(e) {
    this.mask &= ~(1 << e | 0);
  }
  disableAll() {
    this.mask = 0;
  }
  test(e) {
    return (this.mask & e.mask) !== 0;
  }
  isEnabled(e) {
    return (this.mask & (1 << e | 0)) !== 0;
  }
}
let Ol = 0;
const Cs = /* @__PURE__ */ new j(), Jn = /* @__PURE__ */ new qi(), un = /* @__PURE__ */ new st(), or = /* @__PURE__ */ new j(), Di = /* @__PURE__ */ new j(), Bl = /* @__PURE__ */ new j(), kl = /* @__PURE__ */ new qi(), Rs = /* @__PURE__ */ new j(1, 0, 0), Ps = /* @__PURE__ */ new j(0, 1, 0), Us = /* @__PURE__ */ new j(0, 0, 1), Ds = { type: "added" }, Gl = { type: "removed" }, Qn = { type: "childadded", child: null }, fa = { type: "childremoved", child: null };
class gt extends Gn {
  constructor() {
    super(), this.isObject3D = !0, Object.defineProperty(this, "id", { value: Ol++ }), this.uuid = mi(), this.name = "", this.type = "Object3D", this.parent = null, this.children = [], this.up = gt.DEFAULT_UP.clone();
    const e = new j(), t = new mn(), r = new qi(), n = new j(1, 1, 1);
    function i() {
      r.setFromEuler(t, !1);
    }
    function s() {
      t.setFromQuaternion(r, void 0, !1);
    }
    t._onChange(i), r._onChange(s), Object.defineProperties(this, {
      position: {
        configurable: !0,
        enumerable: !0,
        value: e
      },
      rotation: {
        configurable: !0,
        enumerable: !0,
        value: t
      },
      quaternion: {
        configurable: !0,
        enumerable: !0,
        value: r
      },
      scale: {
        configurable: !0,
        enumerable: !0,
        value: n
      },
      modelViewMatrix: {
        value: new st()
      },
      normalMatrix: {
        value: new Ye()
      }
    }), this.matrix = new st(), this.matrixWorld = new st(), this.matrixAutoUpdate = gt.DEFAULT_MATRIX_AUTO_UPDATE, this.matrixWorldAutoUpdate = gt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE, this.matrixWorldNeedsUpdate = !1, this.layers = new Bo(), this.visible = !0, this.castShadow = !1, this.receiveShadow = !1, this.frustumCulled = !0, this.renderOrder = 0, this.animations = [], this.userData = {};
  }
  onBeforeShadow() {
  }
  onAfterShadow() {
  }
  onBeforeRender() {
  }
  onAfterRender() {
  }
  applyMatrix4(e) {
    this.matrixAutoUpdate && this.updateMatrix(), this.matrix.premultiply(e), this.matrix.decompose(this.position, this.quaternion, this.scale);
  }
  applyQuaternion(e) {
    return this.quaternion.premultiply(e), this;
  }
  setRotationFromAxisAngle(e, t) {
    this.quaternion.setFromAxisAngle(e, t);
  }
  setRotationFromEuler(e) {
    this.quaternion.setFromEuler(e, !0);
  }
  setRotationFromMatrix(e) {
    this.quaternion.setFromRotationMatrix(e);
  }
  setRotationFromQuaternion(e) {
    this.quaternion.copy(e);
  }
  rotateOnAxis(e, t) {
    return Jn.setFromAxisAngle(e, t), this.quaternion.multiply(Jn), this;
  }
  rotateOnWorldAxis(e, t) {
    return Jn.setFromAxisAngle(e, t), this.quaternion.premultiply(Jn), this;
  }
  rotateX(e) {
    return this.rotateOnAxis(Rs, e);
  }
  rotateY(e) {
    return this.rotateOnAxis(Ps, e);
  }
  rotateZ(e) {
    return this.rotateOnAxis(Us, e);
  }
  translateOnAxis(e, t) {
    return Cs.copy(e).applyQuaternion(this.quaternion), this.position.add(Cs.multiplyScalar(t)), this;
  }
  translateX(e) {
    return this.translateOnAxis(Rs, e);
  }
  translateY(e) {
    return this.translateOnAxis(Ps, e);
  }
  translateZ(e) {
    return this.translateOnAxis(Us, e);
  }
  localToWorld(e) {
    return this.updateWorldMatrix(!0, !1), e.applyMatrix4(this.matrixWorld);
  }
  worldToLocal(e) {
    return this.updateWorldMatrix(!0, !1), e.applyMatrix4(un.copy(this.matrixWorld).invert());
  }
  lookAt(e, t, r) {
    e.isVector3 ? or.copy(e) : or.set(e, t, r);
    const n = this.parent;
    this.updateWorldMatrix(!0, !1), Di.setFromMatrixPosition(this.matrixWorld), this.isCamera || this.isLight ? un.lookAt(Di, or, this.up) : un.lookAt(or, Di, this.up), this.quaternion.setFromRotationMatrix(un), n && (un.extractRotation(n.matrixWorld), Jn.setFromRotationMatrix(un), this.quaternion.premultiply(Jn.invert()));
  }
  add(e) {
    if (arguments.length > 1) {
      for (let t = 0; t < arguments.length; t++)
        this.add(arguments[t]);
      return this;
    }
    return e === this ? (console.error("THREE.Object3D.add: object can't be added as a child of itself.", e), this) : (e && e.isObject3D ? (e.removeFromParent(), e.parent = this, this.children.push(e), e.dispatchEvent(Ds), Qn.child = e, this.dispatchEvent(Qn), Qn.child = null) : console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", e), this);
  }
  remove(e) {
    if (arguments.length > 1) {
      for (let r = 0; r < arguments.length; r++)
        this.remove(arguments[r]);
      return this;
    }
    const t = this.children.indexOf(e);
    return t !== -1 && (e.parent = null, this.children.splice(t, 1), e.dispatchEvent(Gl), fa.child = e, this.dispatchEvent(fa), fa.child = null), this;
  }
  removeFromParent() {
    const e = this.parent;
    return e !== null && e.remove(this), this;
  }
  clear() {
    return this.remove(...this.children);
  }
  attach(e) {
    return this.updateWorldMatrix(!0, !1), un.copy(this.matrixWorld).invert(), e.parent !== null && (e.parent.updateWorldMatrix(!0, !1), un.multiply(e.parent.matrixWorld)), e.applyMatrix4(un), e.removeFromParent(), e.parent = this, this.children.push(e), e.updateWorldMatrix(!1, !0), e.dispatchEvent(Ds), Qn.child = e, this.dispatchEvent(Qn), Qn.child = null, this;
  }
  getObjectById(e) {
    return this.getObjectByProperty("id", e);
  }
  getObjectByName(e) {
    return this.getObjectByProperty("name", e);
  }
  getObjectByProperty(e, t) {
    if (this[e] === t) return this;
    for (let r = 0, n = this.children.length; r < n; r++) {
      const s = this.children[r].getObjectByProperty(e, t);
      if (s !== void 0)
        return s;
    }
  }
  getObjectsByProperty(e, t, r = []) {
    this[e] === t && r.push(this);
    const n = this.children;
    for (let i = 0, s = n.length; i < s; i++)
      n[i].getObjectsByProperty(e, t, r);
    return r;
  }
  getWorldPosition(e) {
    return this.updateWorldMatrix(!0, !1), e.setFromMatrixPosition(this.matrixWorld);
  }
  getWorldQuaternion(e) {
    return this.updateWorldMatrix(!0, !1), this.matrixWorld.decompose(Di, e, Bl), e;
  }
  getWorldScale(e) {
    return this.updateWorldMatrix(!0, !1), this.matrixWorld.decompose(Di, kl, e), e;
  }
  getWorldDirection(e) {
    this.updateWorldMatrix(!0, !1);
    const t = this.matrixWorld.elements;
    return e.set(t[8], t[9], t[10]).normalize();
  }
  raycast() {
  }
  traverse(e) {
    e(this);
    const t = this.children;
    for (let r = 0, n = t.length; r < n; r++)
      t[r].traverse(e);
  }
  traverseVisible(e) {
    if (this.visible === !1) return;
    e(this);
    const t = this.children;
    for (let r = 0, n = t.length; r < n; r++)
      t[r].traverseVisible(e);
  }
  traverseAncestors(e) {
    const t = this.parent;
    t !== null && (e(t), t.traverseAncestors(e));
  }
  updateMatrix() {
    this.matrix.compose(this.position, this.quaternion, this.scale), this.matrixWorldNeedsUpdate = !0;
  }
  updateMatrixWorld(e) {
    this.matrixAutoUpdate && this.updateMatrix(), (this.matrixWorldNeedsUpdate || e) && (this.matrixWorldAutoUpdate === !0 && (this.parent === null ? this.matrixWorld.copy(this.matrix) : this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix)), this.matrixWorldNeedsUpdate = !1, e = !0);
    const t = this.children;
    for (let r = 0, n = t.length; r < n; r++)
      t[r].updateMatrixWorld(e);
  }
  updateWorldMatrix(e, t) {
    const r = this.parent;
    if (e === !0 && r !== null && r.updateWorldMatrix(!0, !1), this.matrixAutoUpdate && this.updateMatrix(), this.matrixWorldAutoUpdate === !0 && (this.parent === null ? this.matrixWorld.copy(this.matrix) : this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix)), t === !0) {
      const n = this.children;
      for (let i = 0, s = n.length; i < s; i++)
        n[i].updateWorldMatrix(!1, !0);
    }
  }
  toJSON(e) {
    const t = e === void 0 || typeof e == "string", r = {};
    t && (e = {
      geometries: {},
      materials: {},
      textures: {},
      images: {},
      shapes: {},
      skeletons: {},
      animations: {},
      nodes: {}
    }, r.metadata = {
      version: 4.6,
      type: "Object",
      generator: "Object3D.toJSON"
    });
    const n = {};
    n.uuid = this.uuid, n.type = this.type, this.name !== "" && (n.name = this.name), this.castShadow === !0 && (n.castShadow = !0), this.receiveShadow === !0 && (n.receiveShadow = !0), this.visible === !1 && (n.visible = !1), this.frustumCulled === !1 && (n.frustumCulled = !1), this.renderOrder !== 0 && (n.renderOrder = this.renderOrder), Object.keys(this.userData).length > 0 && (n.userData = this.userData), n.layers = this.layers.mask, n.matrix = this.matrix.toArray(), n.up = this.up.toArray(), this.matrixAutoUpdate === !1 && (n.matrixAutoUpdate = !1), this.isInstancedMesh && (n.type = "InstancedMesh", n.count = this.count, n.instanceMatrix = this.instanceMatrix.toJSON(), this.instanceColor !== null && (n.instanceColor = this.instanceColor.toJSON())), this.isBatchedMesh && (n.type = "BatchedMesh", n.perObjectFrustumCulled = this.perObjectFrustumCulled, n.sortObjects = this.sortObjects, n.drawRanges = this._drawRanges, n.reservedRanges = this._reservedRanges, n.visibility = this._visibility, n.active = this._active, n.bounds = this._bounds.map((o) => ({
      boxInitialized: o.boxInitialized,
      boxMin: o.box.min.toArray(),
      boxMax: o.box.max.toArray(),
      sphereInitialized: o.sphereInitialized,
      sphereRadius: o.sphere.radius,
      sphereCenter: o.sphere.center.toArray()
    })), n.maxInstanceCount = this._maxInstanceCount, n.maxVertexCount = this._maxVertexCount, n.maxIndexCount = this._maxIndexCount, n.geometryInitialized = this._geometryInitialized, n.geometryCount = this._geometryCount, n.matricesTexture = this._matricesTexture.toJSON(e), this._colorsTexture !== null && (n.colorsTexture = this._colorsTexture.toJSON(e)), this.boundingSphere !== null && (n.boundingSphere = {
      center: n.boundingSphere.center.toArray(),
      radius: n.boundingSphere.radius
    }), this.boundingBox !== null && (n.boundingBox = {
      min: n.boundingBox.min.toArray(),
      max: n.boundingBox.max.toArray()
    }));
    function i(o, l) {
      return o[l.uuid] === void 0 && (o[l.uuid] = l.toJSON(e)), l.uuid;
    }
    if (this.isScene)
      this.background && (this.background.isColor ? n.background = this.background.toJSON() : this.background.isTexture && (n.background = this.background.toJSON(e).uuid)), this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== !0 && (n.environment = this.environment.toJSON(e).uuid);
    else if (this.isMesh || this.isLine || this.isPoints) {
      n.geometry = i(e.geometries, this.geometry);
      const o = this.geometry.parameters;
      if (o !== void 0 && o.shapes !== void 0) {
        const l = o.shapes;
        if (Array.isArray(l))
          for (let c = 0, u = l.length; c < u; c++) {
            const f = l[c];
            i(e.shapes, f);
          }
        else
          i(e.shapes, l);
      }
    }
    if (this.isSkinnedMesh && (n.bindMode = this.bindMode, n.bindMatrix = this.bindMatrix.toArray(), this.skeleton !== void 0 && (i(e.skeletons, this.skeleton), n.skeleton = this.skeleton.uuid)), this.material !== void 0)
      if (Array.isArray(this.material)) {
        const o = [];
        for (let l = 0, c = this.material.length; l < c; l++)
          o.push(i(e.materials, this.material[l]));
        n.material = o;
      } else
        n.material = i(e.materials, this.material);
    if (this.children.length > 0) {
      n.children = [];
      for (let o = 0; o < this.children.length; o++)
        n.children.push(this.children[o].toJSON(e).object);
    }
    if (this.animations.length > 0) {
      n.animations = [];
      for (let o = 0; o < this.animations.length; o++) {
        const l = this.animations[o];
        n.animations.push(i(e.animations, l));
      }
    }
    if (t) {
      const o = s(e.geometries), l = s(e.materials), c = s(e.textures), u = s(e.images), f = s(e.shapes), h = s(e.skeletons), d = s(e.animations), g = s(e.nodes);
      o.length > 0 && (r.geometries = o), l.length > 0 && (r.materials = l), c.length > 0 && (r.textures = c), u.length > 0 && (r.images = u), f.length > 0 && (r.shapes = f), h.length > 0 && (r.skeletons = h), d.length > 0 && (r.animations = d), g.length > 0 && (r.nodes = g);
    }
    return r.object = n, r;
    function s(o) {
      const l = [];
      for (const c in o) {
        const u = o[c];
        delete u.metadata, l.push(u);
      }
      return l;
    }
  }
  clone(e) {
    return new this.constructor().copy(this, e);
  }
  copy(e, t = !0) {
    if (this.name = e.name, this.up.copy(e.up), this.position.copy(e.position), this.rotation.order = e.rotation.order, this.quaternion.copy(e.quaternion), this.scale.copy(e.scale), this.matrix.copy(e.matrix), this.matrixWorld.copy(e.matrixWorld), this.matrixAutoUpdate = e.matrixAutoUpdate, this.matrixWorldAutoUpdate = e.matrixWorldAutoUpdate, this.matrixWorldNeedsUpdate = e.matrixWorldNeedsUpdate, this.layers.mask = e.layers.mask, this.visible = e.visible, this.castShadow = e.castShadow, this.receiveShadow = e.receiveShadow, this.frustumCulled = e.frustumCulled, this.renderOrder = e.renderOrder, this.animations = e.animations.slice(), this.userData = JSON.parse(JSON.stringify(e.userData)), t === !0)
      for (let r = 0; r < e.children.length; r++) {
        const n = e.children[r];
        this.add(n.clone());
      }
    return this;
  }
}
gt.DEFAULT_UP = /* @__PURE__ */ new j(0, 1, 0);
gt.DEFAULT_MATRIX_AUTO_UPDATE = !0;
gt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = !0;
const Jt = /* @__PURE__ */ new j(), hn = /* @__PURE__ */ new j(), da = /* @__PURE__ */ new j(), fn = /* @__PURE__ */ new j(), $n = /* @__PURE__ */ new j(), ei = /* @__PURE__ */ new j(), Ls = /* @__PURE__ */ new j(), pa = /* @__PURE__ */ new j(), ma = /* @__PURE__ */ new j(), ga = /* @__PURE__ */ new j(), va = /* @__PURE__ */ new ot(), _a = /* @__PURE__ */ new ot(), xa = /* @__PURE__ */ new ot();
class $t {
  constructor(e = new j(), t = new j(), r = new j()) {
    this.a = e, this.b = t, this.c = r;
  }
  static getNormal(e, t, r, n) {
    n.subVectors(r, t), Jt.subVectors(e, t), n.cross(Jt);
    const i = n.lengthSq();
    return i > 0 ? n.multiplyScalar(1 / Math.sqrt(i)) : n.set(0, 0, 0);
  }
  // static/instance method to calculate barycentric coordinates
  // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  static getBarycoord(e, t, r, n, i) {
    Jt.subVectors(n, t), hn.subVectors(r, t), da.subVectors(e, t);
    const s = Jt.dot(Jt), o = Jt.dot(hn), l = Jt.dot(da), c = hn.dot(hn), u = hn.dot(da), f = s * c - o * o;
    if (f === 0)
      return i.set(0, 0, 0), null;
    const h = 1 / f, d = (c * l - o * u) * h, g = (s * u - o * l) * h;
    return i.set(1 - d - g, g, d);
  }
  static containsPoint(e, t, r, n) {
    return this.getBarycoord(e, t, r, n, fn) === null ? !1 : fn.x >= 0 && fn.y >= 0 && fn.x + fn.y <= 1;
  }
  static getInterpolation(e, t, r, n, i, s, o, l) {
    return this.getBarycoord(e, t, r, n, fn) === null ? (l.x = 0, l.y = 0, "z" in l && (l.z = 0), "w" in l && (l.w = 0), null) : (l.setScalar(0), l.addScaledVector(i, fn.x), l.addScaledVector(s, fn.y), l.addScaledVector(o, fn.z), l);
  }
  static getInterpolatedAttribute(e, t, r, n, i, s) {
    return va.setScalar(0), _a.setScalar(0), xa.setScalar(0), va.fromBufferAttribute(e, t), _a.fromBufferAttribute(e, r), xa.fromBufferAttribute(e, n), s.setScalar(0), s.addScaledVector(va, i.x), s.addScaledVector(_a, i.y), s.addScaledVector(xa, i.z), s;
  }
  static isFrontFacing(e, t, r, n) {
    return Jt.subVectors(r, t), hn.subVectors(e, t), Jt.cross(hn).dot(n) < 0;
  }
  set(e, t, r) {
    return this.a.copy(e), this.b.copy(t), this.c.copy(r), this;
  }
  setFromPointsAndIndices(e, t, r, n) {
    return this.a.copy(e[t]), this.b.copy(e[r]), this.c.copy(e[n]), this;
  }
  setFromAttributeAndIndices(e, t, r, n) {
    return this.a.fromBufferAttribute(e, t), this.b.fromBufferAttribute(e, r), this.c.fromBufferAttribute(e, n), this;
  }
  clone() {
    return new this.constructor().copy(this);
  }
  copy(e) {
    return this.a.copy(e.a), this.b.copy(e.b), this.c.copy(e.c), this;
  }
  getArea() {
    return Jt.subVectors(this.c, this.b), hn.subVectors(this.a, this.b), Jt.cross(hn).length() * 0.5;
  }
  getMidpoint(e) {
    return e.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  }
  getNormal(e) {
    return $t.getNormal(this.a, this.b, this.c, e);
  }
  getPlane(e) {
    return e.setFromCoplanarPoints(this.a, this.b, this.c);
  }
  getBarycoord(e, t) {
    return $t.getBarycoord(e, this.a, this.b, this.c, t);
  }
  getInterpolation(e, t, r, n, i) {
    return $t.getInterpolation(e, this.a, this.b, this.c, t, r, n, i);
  }
  containsPoint(e) {
    return $t.containsPoint(e, this.a, this.b, this.c);
  }
  isFrontFacing(e) {
    return $t.isFrontFacing(this.a, this.b, this.c, e);
  }
  intersectsBox(e) {
    return e.intersectsTriangle(this);
  }
  closestPointToPoint(e, t) {
    const r = this.a, n = this.b, i = this.c;
    let s, o;
    $n.subVectors(n, r), ei.subVectors(i, r), pa.subVectors(e, r);
    const l = $n.dot(pa), c = ei.dot(pa);
    if (l <= 0 && c <= 0)
      return t.copy(r);
    ma.subVectors(e, n);
    const u = $n.dot(ma), f = ei.dot(ma);
    if (u >= 0 && f <= u)
      return t.copy(n);
    const h = l * f - u * c;
    if (h <= 0 && l >= 0 && u <= 0)
      return s = l / (l - u), t.copy(r).addScaledVector($n, s);
    ga.subVectors(e, i);
    const d = $n.dot(ga), g = ei.dot(ga);
    if (g >= 0 && d <= g)
      return t.copy(i);
    const v = d * c - l * g;
    if (v <= 0 && c >= 0 && g <= 0)
      return o = c / (c - g), t.copy(r).addScaledVector(ei, o);
    const m = u * g - d * f;
    if (m <= 0 && f - u >= 0 && d - g >= 0)
      return Ls.subVectors(i, n), o = (f - u) / (f - u + (d - g)), t.copy(n).addScaledVector(Ls, o);
    const p = 1 / (m + v + h);
    return s = v * p, o = h * p, t.copy(r).addScaledVector($n, s).addScaledVector(ei, o);
  }
  equals(e) {
    return e.a.equals(this.a) && e.b.equals(this.b) && e.c.equals(this.c);
  }
}
const ko = {
  aliceblue: 15792383,
  antiquewhite: 16444375,
  aqua: 65535,
  aquamarine: 8388564,
  azure: 15794175,
  beige: 16119260,
  bisque: 16770244,
  black: 0,
  blanchedalmond: 16772045,
  blue: 255,
  blueviolet: 9055202,
  brown: 10824234,
  burlywood: 14596231,
  cadetblue: 6266528,
  chartreuse: 8388352,
  chocolate: 13789470,
  coral: 16744272,
  cornflowerblue: 6591981,
  cornsilk: 16775388,
  crimson: 14423100,
  cyan: 65535,
  darkblue: 139,
  darkcyan: 35723,
  darkgoldenrod: 12092939,
  darkgray: 11119017,
  darkgreen: 25600,
  darkgrey: 11119017,
  darkkhaki: 12433259,
  darkmagenta: 9109643,
  darkolivegreen: 5597999,
  darkorange: 16747520,
  darkorchid: 10040012,
  darkred: 9109504,
  darksalmon: 15308410,
  darkseagreen: 9419919,
  darkslateblue: 4734347,
  darkslategray: 3100495,
  darkslategrey: 3100495,
  darkturquoise: 52945,
  darkviolet: 9699539,
  deeppink: 16716947,
  deepskyblue: 49151,
  dimgray: 6908265,
  dimgrey: 6908265,
  dodgerblue: 2003199,
  firebrick: 11674146,
  floralwhite: 16775920,
  forestgreen: 2263842,
  fuchsia: 16711935,
  gainsboro: 14474460,
  ghostwhite: 16316671,
  gold: 16766720,
  goldenrod: 14329120,
  gray: 8421504,
  green: 32768,
  greenyellow: 11403055,
  grey: 8421504,
  honeydew: 15794160,
  hotpink: 16738740,
  indianred: 13458524,
  indigo: 4915330,
  ivory: 16777200,
  khaki: 15787660,
  lavender: 15132410,
  lavenderblush: 16773365,
  lawngreen: 8190976,
  lemonchiffon: 16775885,
  lightblue: 11393254,
  lightcoral: 15761536,
  lightcyan: 14745599,
  lightgoldenrodyellow: 16448210,
  lightgray: 13882323,
  lightgreen: 9498256,
  lightgrey: 13882323,
  lightpink: 16758465,
  lightsalmon: 16752762,
  lightseagreen: 2142890,
  lightskyblue: 8900346,
  lightslategray: 7833753,
  lightslategrey: 7833753,
  lightsteelblue: 11584734,
  lightyellow: 16777184,
  lime: 65280,
  limegreen: 3329330,
  linen: 16445670,
  magenta: 16711935,
  maroon: 8388608,
  mediumaquamarine: 6737322,
  mediumblue: 205,
  mediumorchid: 12211667,
  mediumpurple: 9662683,
  mediumseagreen: 3978097,
  mediumslateblue: 8087790,
  mediumspringgreen: 64154,
  mediumturquoise: 4772300,
  mediumvioletred: 13047173,
  midnightblue: 1644912,
  mintcream: 16121850,
  mistyrose: 16770273,
  moccasin: 16770229,
  navajowhite: 16768685,
  navy: 128,
  oldlace: 16643558,
  olive: 8421376,
  olivedrab: 7048739,
  orange: 16753920,
  orangered: 16729344,
  orchid: 14315734,
  palegoldenrod: 15657130,
  palegreen: 10025880,
  paleturquoise: 11529966,
  palevioletred: 14381203,
  papayawhip: 16773077,
  peachpuff: 16767673,
  peru: 13468991,
  pink: 16761035,
  plum: 14524637,
  powderblue: 11591910,
  purple: 8388736,
  rebeccapurple: 6697881,
  red: 16711680,
  rosybrown: 12357519,
  royalblue: 4286945,
  saddlebrown: 9127187,
  salmon: 16416882,
  sandybrown: 16032864,
  seagreen: 3050327,
  seashell: 16774638,
  sienna: 10506797,
  silver: 12632256,
  skyblue: 8900331,
  slateblue: 6970061,
  slategray: 7372944,
  slategrey: 7372944,
  snow: 16775930,
  springgreen: 65407,
  steelblue: 4620980,
  tan: 13808780,
  teal: 32896,
  thistle: 14204888,
  tomato: 16737095,
  turquoise: 4251856,
  violet: 15631086,
  wheat: 16113331,
  white: 16777215,
  whitesmoke: 16119285,
  yellow: 16776960,
  yellowgreen: 10145074
}, Mn = { h: 0, s: 0, l: 0 }, lr = { h: 0, s: 0, l: 0 };
function Sa(a, e, t) {
  return t < 0 && (t += 1), t > 1 && (t -= 1), t < 1 / 6 ? a + (e - a) * 6 * t : t < 1 / 2 ? e : t < 2 / 3 ? a + (e - a) * 6 * (2 / 3 - t) : a;
}
class Ke {
  constructor(e, t, r) {
    return this.isColor = !0, this.r = 1, this.g = 1, this.b = 1, this.set(e, t, r);
  }
  set(e, t, r) {
    if (t === void 0 && r === void 0) {
      const n = e;
      n && n.isColor ? this.copy(n) : typeof n == "number" ? this.setHex(n) : typeof n == "string" && this.setStyle(n);
    } else
      this.setRGB(e, t, r);
    return this;
  }
  setScalar(e) {
    return this.r = e, this.g = e, this.b = e, this;
  }
  setHex(e, t = Xt) {
    return e = Math.floor(e), this.r = (e >> 16 & 255) / 255, this.g = (e >> 8 & 255) / 255, this.b = (e & 255) / 255, $e.toWorkingColorSpace(this, t), this;
  }
  setRGB(e, t, r, n = $e.workingColorSpace) {
    return this.r = e, this.g = t, this.b = r, $e.toWorkingColorSpace(this, n), this;
  }
  setHSL(e, t, r, n = $e.workingColorSpace) {
    if (e = Tl(e, 1), t = bt(t, 0, 1), r = bt(r, 0, 1), t === 0)
      this.r = this.g = this.b = r;
    else {
      const i = r <= 0.5 ? r * (1 + t) : r + t - r * t, s = 2 * r - i;
      this.r = Sa(s, i, e + 1 / 3), this.g = Sa(s, i, e), this.b = Sa(s, i, e - 1 / 3);
    }
    return $e.toWorkingColorSpace(this, n), this;
  }
  setStyle(e, t = Xt) {
    function r(i) {
      i !== void 0 && parseFloat(i) < 1 && console.warn("THREE.Color: Alpha component of " + e + " will be ignored.");
    }
    let n;
    if (n = /^(\w+)\(([^\)]*)\)/.exec(e)) {
      let i;
      const s = n[1], o = n[2];
      switch (s) {
        case "rgb":
        case "rgba":
          if (i = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))
            return r(i[4]), this.setRGB(
              Math.min(255, parseInt(i[1], 10)) / 255,
              Math.min(255, parseInt(i[2], 10)) / 255,
              Math.min(255, parseInt(i[3], 10)) / 255,
              t
            );
          if (i = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))
            return r(i[4]), this.setRGB(
              Math.min(100, parseInt(i[1], 10)) / 100,
              Math.min(100, parseInt(i[2], 10)) / 100,
              Math.min(100, parseInt(i[3], 10)) / 100,
              t
            );
          break;
        case "hsl":
        case "hsla":
          if (i = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))
            return r(i[4]), this.setHSL(
              parseFloat(i[1]) / 360,
              parseFloat(i[2]) / 100,
              parseFloat(i[3]) / 100,
              t
            );
          break;
        default:
          console.warn("THREE.Color: Unknown color model " + e);
      }
    } else if (n = /^\#([A-Fa-f\d]+)$/.exec(e)) {
      const i = n[1], s = i.length;
      if (s === 3)
        return this.setRGB(
          parseInt(i.charAt(0), 16) / 15,
          parseInt(i.charAt(1), 16) / 15,
          parseInt(i.charAt(2), 16) / 15,
          t
        );
      if (s === 6)
        return this.setHex(parseInt(i, 16), t);
      console.warn("THREE.Color: Invalid hex color " + e);
    } else if (e && e.length > 0)
      return this.setColorName(e, t);
    return this;
  }
  setColorName(e, t = Xt) {
    const r = ko[e.toLowerCase()];
    return r !== void 0 ? this.setHex(r, t) : console.warn("THREE.Color: Unknown color " + e), this;
  }
  clone() {
    return new this.constructor(this.r, this.g, this.b);
  }
  copy(e) {
    return this.r = e.r, this.g = e.g, this.b = e.b, this;
  }
  copySRGBToLinear(e) {
    return this.r = pn(e.r), this.g = pn(e.g), this.b = pn(e.b), this;
  }
  copyLinearToSRGB(e) {
    return this.r = hi(e.r), this.g = hi(e.g), this.b = hi(e.b), this;
  }
  convertSRGBToLinear() {
    return this.copySRGBToLinear(this), this;
  }
  convertLinearToSRGB() {
    return this.copyLinearToSRGB(this), this;
  }
  getHex(e = Xt) {
    return $e.fromWorkingColorSpace(Tt.copy(this), e), Math.round(bt(Tt.r * 255, 0, 255)) * 65536 + Math.round(bt(Tt.g * 255, 0, 255)) * 256 + Math.round(bt(Tt.b * 255, 0, 255));
  }
  getHexString(e = Xt) {
    return ("000000" + this.getHex(e).toString(16)).slice(-6);
  }
  getHSL(e, t = $e.workingColorSpace) {
    $e.fromWorkingColorSpace(Tt.copy(this), t);
    const r = Tt.r, n = Tt.g, i = Tt.b, s = Math.max(r, n, i), o = Math.min(r, n, i);
    let l, c;
    const u = (o + s) / 2;
    if (o === s)
      l = 0, c = 0;
    else {
      const f = s - o;
      switch (c = u <= 0.5 ? f / (s + o) : f / (2 - s - o), s) {
        case r:
          l = (n - i) / f + (n < i ? 6 : 0);
          break;
        case n:
          l = (i - r) / f + 2;
          break;
        case i:
          l = (r - n) / f + 4;
          break;
      }
      l /= 6;
    }
    return e.h = l, e.s = c, e.l = u, e;
  }
  getRGB(e, t = $e.workingColorSpace) {
    return $e.fromWorkingColorSpace(Tt.copy(this), t), e.r = Tt.r, e.g = Tt.g, e.b = Tt.b, e;
  }
  getStyle(e = Xt) {
    $e.fromWorkingColorSpace(Tt.copy(this), e);
    const t = Tt.r, r = Tt.g, n = Tt.b;
    return e !== Xt ? `color(${e} ${t.toFixed(3)} ${r.toFixed(3)} ${n.toFixed(3)})` : `rgb(${Math.round(t * 255)},${Math.round(r * 255)},${Math.round(n * 255)})`;
  }
  offsetHSL(e, t, r) {
    return this.getHSL(Mn), this.setHSL(Mn.h + e, Mn.s + t, Mn.l + r);
  }
  add(e) {
    return this.r += e.r, this.g += e.g, this.b += e.b, this;
  }
  addColors(e, t) {
    return this.r = e.r + t.r, this.g = e.g + t.g, this.b = e.b + t.b, this;
  }
  addScalar(e) {
    return this.r += e, this.g += e, this.b += e, this;
  }
  sub(e) {
    return this.r = Math.max(0, this.r - e.r), this.g = Math.max(0, this.g - e.g), this.b = Math.max(0, this.b - e.b), this;
  }
  multiply(e) {
    return this.r *= e.r, this.g *= e.g, this.b *= e.b, this;
  }
  multiplyScalar(e) {
    return this.r *= e, this.g *= e, this.b *= e, this;
  }
  lerp(e, t) {
    return this.r += (e.r - this.r) * t, this.g += (e.g - this.g) * t, this.b += (e.b - this.b) * t, this;
  }
  lerpColors(e, t, r) {
    return this.r = e.r + (t.r - e.r) * r, this.g = e.g + (t.g - e.g) * r, this.b = e.b + (t.b - e.b) * r, this;
  }
  lerpHSL(e, t) {
    this.getHSL(Mn), e.getHSL(lr);
    const r = ia(Mn.h, lr.h, t), n = ia(Mn.s, lr.s, t), i = ia(Mn.l, lr.l, t);
    return this.setHSL(r, n, i), this;
  }
  setFromVector3(e) {
    return this.r = e.x, this.g = e.y, this.b = e.z, this;
  }
  applyMatrix3(e) {
    const t = this.r, r = this.g, n = this.b, i = e.elements;
    return this.r = i[0] * t + i[3] * r + i[6] * n, this.g = i[1] * t + i[4] * r + i[7] * n, this.b = i[2] * t + i[5] * r + i[8] * n, this;
  }
  equals(e) {
    return e.r === this.r && e.g === this.g && e.b === this.b;
  }
  fromArray(e, t = 0) {
    return this.r = e[t], this.g = e[t + 1], this.b = e[t + 2], this;
  }
  toArray(e = [], t = 0) {
    return e[t] = this.r, e[t + 1] = this.g, e[t + 2] = this.b, e;
  }
  fromBufferAttribute(e, t) {
    return this.r = e.getX(t), this.g = e.getY(t), this.b = e.getZ(t), this;
  }
  toJSON() {
    return this.getHex();
  }
  *[Symbol.iterator]() {
    yield this.r, yield this.g, yield this.b;
  }
}
const Tt = /* @__PURE__ */ new Ke();
Ke.NAMES = ko;
let zl = 0;
class vi extends Gn {
  static get type() {
    return "Material";
  }
  get type() {
    return this.constructor.type;
  }
  set type(e) {
  }
  constructor() {
    super(), this.isMaterial = !0, Object.defineProperty(this, "id", { value: zl++ }), this.uuid = mi(), this.name = "", this.blending = 1, this.side = 0, this.vertexColors = !1, this.opacity = 1, this.transparent = !1, this.alphaHash = !1, this.blendSrc = 204, this.blendDst = 205, this.blendEquation = 100, this.blendSrcAlpha = null, this.blendDstAlpha = null, this.blendEquationAlpha = null, this.blendColor = new Ke(0, 0, 0), this.blendAlpha = 0, this.depthFunc = 3, this.depthTest = !0, this.depthWrite = !0, this.stencilWriteMask = 255, this.stencilFunc = 519, this.stencilRef = 0, this.stencilFuncMask = 255, this.stencilFail = 7680, this.stencilZFail = 7680, this.stencilZPass = 7680, this.stencilWrite = !1, this.clippingPlanes = null, this.clipIntersection = !1, this.clipShadows = !1, this.shadowSide = null, this.colorWrite = !0, this.precision = null, this.polygonOffset = !1, this.polygonOffsetFactor = 0, this.polygonOffsetUnits = 0, this.dithering = !1, this.alphaToCoverage = !1, this.premultipliedAlpha = !1, this.forceSinglePass = !1, this.visible = !0, this.toneMapped = !0, this.userData = {}, this.version = 0, this._alphaTest = 0;
  }
  get alphaTest() {
    return this._alphaTest;
  }
  set alphaTest(e) {
    this._alphaTest > 0 != e > 0 && this.version++, this._alphaTest = e;
  }
  // onBeforeRender and onBeforeCompile only supported in WebGLRenderer
  onBeforeRender() {
  }
  onBeforeCompile() {
  }
  customProgramCacheKey() {
    return this.onBeforeCompile.toString();
  }
  setValues(e) {
    if (e !== void 0)
      for (const t in e) {
        const r = e[t];
        if (r === void 0) {
          console.warn(`THREE.Material: parameter '${t}' has value of undefined.`);
          continue;
        }
        const n = this[t];
        if (n === void 0) {
          console.warn(`THREE.Material: '${t}' is not a property of THREE.${this.type}.`);
          continue;
        }
        n && n.isColor ? n.set(r) : n && n.isVector3 && r && r.isVector3 ? n.copy(r) : this[t] = r;
      }
  }
  toJSON(e) {
    const t = e === void 0 || typeof e == "string";
    t && (e = {
      textures: {},
      images: {}
    });
    const r = {
      metadata: {
        version: 4.6,
        type: "Material",
        generator: "Material.toJSON"
      }
    };
    r.uuid = this.uuid, r.type = this.type, this.name !== "" && (r.name = this.name), this.color && this.color.isColor && (r.color = this.color.getHex()), this.roughness !== void 0 && (r.roughness = this.roughness), this.metalness !== void 0 && (r.metalness = this.metalness), this.sheen !== void 0 && (r.sheen = this.sheen), this.sheenColor && this.sheenColor.isColor && (r.sheenColor = this.sheenColor.getHex()), this.sheenRoughness !== void 0 && (r.sheenRoughness = this.sheenRoughness), this.emissive && this.emissive.isColor && (r.emissive = this.emissive.getHex()), this.emissiveIntensity !== void 0 && this.emissiveIntensity !== 1 && (r.emissiveIntensity = this.emissiveIntensity), this.specular && this.specular.isColor && (r.specular = this.specular.getHex()), this.specularIntensity !== void 0 && (r.specularIntensity = this.specularIntensity), this.specularColor && this.specularColor.isColor && (r.specularColor = this.specularColor.getHex()), this.shininess !== void 0 && (r.shininess = this.shininess), this.clearcoat !== void 0 && (r.clearcoat = this.clearcoat), this.clearcoatRoughness !== void 0 && (r.clearcoatRoughness = this.clearcoatRoughness), this.clearcoatMap && this.clearcoatMap.isTexture && (r.clearcoatMap = this.clearcoatMap.toJSON(e).uuid), this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture && (r.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(e).uuid), this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture && (r.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(e).uuid, r.clearcoatNormalScale = this.clearcoatNormalScale.toArray()), this.dispersion !== void 0 && (r.dispersion = this.dispersion), this.iridescence !== void 0 && (r.iridescence = this.iridescence), this.iridescenceIOR !== void 0 && (r.iridescenceIOR = this.iridescenceIOR), this.iridescenceThicknessRange !== void 0 && (r.iridescenceThicknessRange = this.iridescenceThicknessRange), this.iridescenceMap && this.iridescenceMap.isTexture && (r.iridescenceMap = this.iridescenceMap.toJSON(e).uuid), this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture && (r.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON(e).uuid), this.anisotropy !== void 0 && (r.anisotropy = this.anisotropy), this.anisotropyRotation !== void 0 && (r.anisotropyRotation = this.anisotropyRotation), this.anisotropyMap && this.anisotropyMap.isTexture && (r.anisotropyMap = this.anisotropyMap.toJSON(e).uuid), this.map && this.map.isTexture && (r.map = this.map.toJSON(e).uuid), this.matcap && this.matcap.isTexture && (r.matcap = this.matcap.toJSON(e).uuid), this.alphaMap && this.alphaMap.isTexture && (r.alphaMap = this.alphaMap.toJSON(e).uuid), this.lightMap && this.lightMap.isTexture && (r.lightMap = this.lightMap.toJSON(e).uuid, r.lightMapIntensity = this.lightMapIntensity), this.aoMap && this.aoMap.isTexture && (r.aoMap = this.aoMap.toJSON(e).uuid, r.aoMapIntensity = this.aoMapIntensity), this.bumpMap && this.bumpMap.isTexture && (r.bumpMap = this.bumpMap.toJSON(e).uuid, r.bumpScale = this.bumpScale), this.normalMap && this.normalMap.isTexture && (r.normalMap = this.normalMap.toJSON(e).uuid, r.normalMapType = this.normalMapType, r.normalScale = this.normalScale.toArray()), this.displacementMap && this.displacementMap.isTexture && (r.displacementMap = this.displacementMap.toJSON(e).uuid, r.displacementScale = this.displacementScale, r.displacementBias = this.displacementBias), this.roughnessMap && this.roughnessMap.isTexture && (r.roughnessMap = this.roughnessMap.toJSON(e).uuid), this.metalnessMap && this.metalnessMap.isTexture && (r.metalnessMap = this.metalnessMap.toJSON(e).uuid), this.emissiveMap && this.emissiveMap.isTexture && (r.emissiveMap = this.emissiveMap.toJSON(e).uuid), this.specularMap && this.specularMap.isTexture && (r.specularMap = this.specularMap.toJSON(e).uuid), this.specularIntensityMap && this.specularIntensityMap.isTexture && (r.specularIntensityMap = this.specularIntensityMap.toJSON(e).uuid), this.specularColorMap && this.specularColorMap.isTexture && (r.specularColorMap = this.specularColorMap.toJSON(e).uuid), this.envMap && this.envMap.isTexture && (r.envMap = this.envMap.toJSON(e).uuid, this.combine !== void 0 && (r.combine = this.combine)), this.envMapRotation !== void 0 && (r.envMapRotation = this.envMapRotation.toArray()), this.envMapIntensity !== void 0 && (r.envMapIntensity = this.envMapIntensity), this.reflectivity !== void 0 && (r.reflectivity = this.reflectivity), this.refractionRatio !== void 0 && (r.refractionRatio = this.refractionRatio), this.gradientMap && this.gradientMap.isTexture && (r.gradientMap = this.gradientMap.toJSON(e).uuid), this.transmission !== void 0 && (r.transmission = this.transmission), this.transmissionMap && this.transmissionMap.isTexture && (r.transmissionMap = this.transmissionMap.toJSON(e).uuid), this.thickness !== void 0 && (r.thickness = this.thickness), this.thicknessMap && this.thicknessMap.isTexture && (r.thicknessMap = this.thicknessMap.toJSON(e).uuid), this.attenuationDistance !== void 0 && this.attenuationDistance !== 1 / 0 && (r.attenuationDistance = this.attenuationDistance), this.attenuationColor !== void 0 && (r.attenuationColor = this.attenuationColor.getHex()), this.size !== void 0 && (r.size = this.size), this.shadowSide !== null && (r.shadowSide = this.shadowSide), this.sizeAttenuation !== void 0 && (r.sizeAttenuation = this.sizeAttenuation), this.blending !== 1 && (r.blending = this.blending), this.side !== 0 && (r.side = this.side), this.vertexColors === !0 && (r.vertexColors = !0), this.opacity < 1 && (r.opacity = this.opacity), this.transparent === !0 && (r.transparent = !0), this.blendSrc !== 204 && (r.blendSrc = this.blendSrc), this.blendDst !== 205 && (r.blendDst = this.blendDst), this.blendEquation !== 100 && (r.blendEquation = this.blendEquation), this.blendSrcAlpha !== null && (r.blendSrcAlpha = this.blendSrcAlpha), this.blendDstAlpha !== null && (r.blendDstAlpha = this.blendDstAlpha), this.blendEquationAlpha !== null && (r.blendEquationAlpha = this.blendEquationAlpha), this.blendColor && this.blendColor.isColor && (r.blendColor = this.blendColor.getHex()), this.blendAlpha !== 0 && (r.blendAlpha = this.blendAlpha), this.depthFunc !== 3 && (r.depthFunc = this.depthFunc), this.depthTest === !1 && (r.depthTest = this.depthTest), this.depthWrite === !1 && (r.depthWrite = this.depthWrite), this.colorWrite === !1 && (r.colorWrite = this.colorWrite), this.stencilWriteMask !== 255 && (r.stencilWriteMask = this.stencilWriteMask), this.stencilFunc !== 519 && (r.stencilFunc = this.stencilFunc), this.stencilRef !== 0 && (r.stencilRef = this.stencilRef), this.stencilFuncMask !== 255 && (r.stencilFuncMask = this.stencilFuncMask), this.stencilFail !== 7680 && (r.stencilFail = this.stencilFail), this.stencilZFail !== 7680 && (r.stencilZFail = this.stencilZFail), this.stencilZPass !== 7680 && (r.stencilZPass = this.stencilZPass), this.stencilWrite === !0 && (r.stencilWrite = this.stencilWrite), this.rotation !== void 0 && this.rotation !== 0 && (r.rotation = this.rotation), this.polygonOffset === !0 && (r.polygonOffset = !0), this.polygonOffsetFactor !== 0 && (r.polygonOffsetFactor = this.polygonOffsetFactor), this.polygonOffsetUnits !== 0 && (r.polygonOffsetUnits = this.polygonOffsetUnits), this.linewidth !== void 0 && this.linewidth !== 1 && (r.linewidth = this.linewidth), this.dashSize !== void 0 && (r.dashSize = this.dashSize), this.gapSize !== void 0 && (r.gapSize = this.gapSize), this.scale !== void 0 && (r.scale = this.scale), this.dithering === !0 && (r.dithering = !0), this.alphaTest > 0 && (r.alphaTest = this.alphaTest), this.alphaHash === !0 && (r.alphaHash = !0), this.alphaToCoverage === !0 && (r.alphaToCoverage = !0), this.premultipliedAlpha === !0 && (r.premultipliedAlpha = !0), this.forceSinglePass === !0 && (r.forceSinglePass = !0), this.wireframe === !0 && (r.wireframe = !0), this.wireframeLinewidth > 1 && (r.wireframeLinewidth = this.wireframeLinewidth), this.wireframeLinecap !== "round" && (r.wireframeLinecap = this.wireframeLinecap), this.wireframeLinejoin !== "round" && (r.wireframeLinejoin = this.wireframeLinejoin), this.flatShading === !0 && (r.flatShading = !0), this.visible === !1 && (r.visible = !1), this.toneMapped === !1 && (r.toneMapped = !1), this.fog === !1 && (r.fog = !1), Object.keys(this.userData).length > 0 && (r.userData = this.userData);
    function n(i) {
      const s = [];
      for (const o in i) {
        const l = i[o];
        delete l.metadata, s.push(l);
      }
      return s;
    }
    if (t) {
      const i = n(e.textures), s = n(e.images);
      i.length > 0 && (r.textures = i), s.length > 0 && (r.images = s);
    }
    return r;
  }
  clone() {
    return new this.constructor().copy(this);
  }
  copy(e) {
    this.name = e.name, this.blending = e.blending, this.side = e.side, this.vertexColors = e.vertexColors, this.opacity = e.opacity, this.transparent = e.transparent, this.blendSrc = e.blendSrc, this.blendDst = e.blendDst, this.blendEquation = e.blendEquation, this.blendSrcAlpha = e.blendSrcAlpha, this.blendDstAlpha = e.blendDstAlpha, this.blendEquationAlpha = e.blendEquationAlpha, this.blendColor.copy(e.blendColor), this.blendAlpha = e.blendAlpha, this.depthFunc = e.depthFunc, this.depthTest = e.depthTest, this.depthWrite = e.depthWrite, this.stencilWriteMask = e.stencilWriteMask, this.stencilFunc = e.stencilFunc, this.stencilRef = e.stencilRef, this.stencilFuncMask = e.stencilFuncMask, this.stencilFail = e.stencilFail, this.stencilZFail = e.stencilZFail, this.stencilZPass = e.stencilZPass, this.stencilWrite = e.stencilWrite;
    const t = e.clippingPlanes;
    let r = null;
    if (t !== null) {
      const n = t.length;
      r = new Array(n);
      for (let i = 0; i !== n; ++i)
        r[i] = t[i].clone();
    }
    return this.clippingPlanes = r, this.clipIntersection = e.clipIntersection, this.clipShadows = e.clipShadows, this.shadowSide = e.shadowSide, this.colorWrite = e.colorWrite, this.precision = e.precision, this.polygonOffset = e.polygonOffset, this.polygonOffsetFactor = e.polygonOffsetFactor, this.polygonOffsetUnits = e.polygonOffsetUnits, this.dithering = e.dithering, this.alphaTest = e.alphaTest, this.alphaHash = e.alphaHash, this.alphaToCoverage = e.alphaToCoverage, this.premultipliedAlpha = e.premultipliedAlpha, this.forceSinglePass = e.forceSinglePass, this.visible = e.visible, this.toneMapped = e.toneMapped, this.userData = JSON.parse(JSON.stringify(e.userData)), this;
  }
  dispose() {
    this.dispatchEvent({ type: "dispose" });
  }
  set needsUpdate(e) {
    e === !0 && this.version++;
  }
  onBuild() {
    console.warn("Material: onBuild() has been removed.");
  }
}
class Vi extends vi {
  static get type() {
    return "MeshBasicMaterial";
  }
  constructor(e) {
    super(), this.isMeshBasicMaterial = !0, this.color = new Ke(16777215), this.map = null, this.lightMap = null, this.lightMapIntensity = 1, this.aoMap = null, this.aoMapIntensity = 1, this.specularMap = null, this.alphaMap = null, this.envMap = null, this.envMapRotation = new mn(), this.combine = 0, this.reflectivity = 1, this.refractionRatio = 0.98, this.wireframe = !1, this.wireframeLinewidth = 1, this.wireframeLinecap = "round", this.wireframeLinejoin = "round", this.fog = !0, this.setValues(e);
  }
  copy(e) {
    return super.copy(e), this.color.copy(e.color), this.map = e.map, this.lightMap = e.lightMap, this.lightMapIntensity = e.lightMapIntensity, this.aoMap = e.aoMap, this.aoMapIntensity = e.aoMapIntensity, this.specularMap = e.specularMap, this.alphaMap = e.alphaMap, this.envMap = e.envMap, this.envMapRotation.copy(e.envMapRotation), this.combine = e.combine, this.reflectivity = e.reflectivity, this.refractionRatio = e.refractionRatio, this.wireframe = e.wireframe, this.wireframeLinewidth = e.wireframeLinewidth, this.wireframeLinecap = e.wireframeLinecap, this.wireframeLinejoin = e.wireframeLinejoin, this.fog = e.fog, this;
  }
}
const ht = /* @__PURE__ */ new j(), cr = /* @__PURE__ */ new Ce();
class en {
  constructor(e, t, r = !1) {
    if (Array.isArray(e))
      throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");
    this.isBufferAttribute = !0, this.name = "", this.array = e, this.itemSize = t, this.count = e !== void 0 ? e.length / t : 0, this.normalized = r, this.usage = 35044, this.updateRanges = [], this.gpuType = 1015, this.version = 0;
  }
  onUploadCallback() {
  }
  set needsUpdate(e) {
    e === !0 && this.version++;
  }
  setUsage(e) {
    return this.usage = e, this;
  }
  addUpdateRange(e, t) {
    this.updateRanges.push({ start: e, count: t });
  }
  clearUpdateRanges() {
    this.updateRanges.length = 0;
  }
  copy(e) {
    return this.name = e.name, this.array = new e.array.constructor(e.array), this.itemSize = e.itemSize, this.count = e.count, this.normalized = e.normalized, this.usage = e.usage, this.gpuType = e.gpuType, this;
  }
  copyAt(e, t, r) {
    e *= this.itemSize, r *= t.itemSize;
    for (let n = 0, i = this.itemSize; n < i; n++)
      this.array[e + n] = t.array[r + n];
    return this;
  }
  copyArray(e) {
    return this.array.set(e), this;
  }
  applyMatrix3(e) {
    if (this.itemSize === 2)
      for (let t = 0, r = this.count; t < r; t++)
        cr.fromBufferAttribute(this, t), cr.applyMatrix3(e), this.setXY(t, cr.x, cr.y);
    else if (this.itemSize === 3)
      for (let t = 0, r = this.count; t < r; t++)
        ht.fromBufferAttribute(this, t), ht.applyMatrix3(e), this.setXYZ(t, ht.x, ht.y, ht.z);
    return this;
  }
  applyMatrix4(e) {
    for (let t = 0, r = this.count; t < r; t++)
      ht.fromBufferAttribute(this, t), ht.applyMatrix4(e), this.setXYZ(t, ht.x, ht.y, ht.z);
    return this;
  }
  applyNormalMatrix(e) {
    for (let t = 0, r = this.count; t < r; t++)
      ht.fromBufferAttribute(this, t), ht.applyNormalMatrix(e), this.setXYZ(t, ht.x, ht.y, ht.z);
    return this;
  }
  transformDirection(e) {
    for (let t = 0, r = this.count; t < r; t++)
      ht.fromBufferAttribute(this, t), ht.transformDirection(e), this.setXYZ(t, ht.x, ht.y, ht.z);
    return this;
  }
  set(e, t = 0) {
    return this.array.set(e, t), this;
  }
  getComponent(e, t) {
    let r = this.array[e * this.itemSize + t];
    return this.normalized && (r = Ri(r, this.array)), r;
  }
  setComponent(e, t, r) {
    return this.normalized && (r = It(r, this.array)), this.array[e * this.itemSize + t] = r, this;
  }
  getX(e) {
    let t = this.array[e * this.itemSize];
    return this.normalized && (t = Ri(t, this.array)), t;
  }
  setX(e, t) {
    return this.normalized && (t = It(t, this.array)), this.array[e * this.itemSize] = t, this;
  }
  getY(e) {
    let t = this.array[e * this.itemSize + 1];
    return this.normalized && (t = Ri(t, this.array)), t;
  }
  setY(e, t) {
    return this.normalized && (t = It(t, this.array)), this.array[e * this.itemSize + 1] = t, this;
  }
  getZ(e) {
    let t = this.array[e * this.itemSize + 2];
    return this.normalized && (t = Ri(t, this.array)), t;
  }
  setZ(e, t) {
    return this.normalized && (t = It(t, this.array)), this.array[e * this.itemSize + 2] = t, this;
  }
  getW(e) {
    let t = this.array[e * this.itemSize + 3];
    return this.normalized && (t = Ri(t, this.array)), t;
  }
  setW(e, t) {
    return this.normalized && (t = It(t, this.array)), this.array[e * this.itemSize + 3] = t, this;
  }
  setXY(e, t, r) {
    return e *= this.itemSize, this.normalized && (t = It(t, this.array), r = It(r, this.array)), this.array[e + 0] = t, this.array[e + 1] = r, this;
  }
  setXYZ(e, t, r, n) {
    return e *= this.itemSize, this.normalized && (t = It(t, this.array), r = It(r, this.array), n = It(n, this.array)), this.array[e + 0] = t, this.array[e + 1] = r, this.array[e + 2] = n, this;
  }
  setXYZW(e, t, r, n, i) {
    return e *= this.itemSize, this.normalized && (t = It(t, this.array), r = It(r, this.array), n = It(n, this.array), i = It(i, this.array)), this.array[e + 0] = t, this.array[e + 1] = r, this.array[e + 2] = n, this.array[e + 3] = i, this;
  }
  onUpload(e) {
    return this.onUploadCallback = e, this;
  }
  clone() {
    return new this.constructor(this.array, this.itemSize).copy(this);
  }
  toJSON() {
    const e = {
      itemSize: this.itemSize,
      type: this.array.constructor.name,
      array: Array.from(this.array),
      normalized: this.normalized
    };
    return this.name !== "" && (e.name = this.name), this.usage !== 35044 && (e.usage = this.usage), e;
  }
}
class Go extends en {
  constructor(e, t, r) {
    super(new Uint16Array(e), t, r);
  }
}
class zo extends en {
  constructor(e, t, r) {
    super(new Uint32Array(e), t, r);
  }
}
class tn extends en {
  constructor(e, t, r) {
    super(new Float32Array(e), t, r);
  }
}
let Vl = 0;
const Wt = /* @__PURE__ */ new st(), ya = /* @__PURE__ */ new gt(), ti = /* @__PURE__ */ new j(), Vt = /* @__PURE__ */ new An(), Li = /* @__PURE__ */ new An(), mt = /* @__PURE__ */ new j();
class St extends Gn {
  constructor() {
    super(), this.isBufferGeometry = !0, Object.defineProperty(this, "id", { value: Vl++ }), this.uuid = mi(), this.name = "", this.type = "BufferGeometry", this.index = null, this.indirect = null, this.attributes = {}, this.morphAttributes = {}, this.morphTargetsRelative = !1, this.groups = [], this.boundingBox = null, this.boundingSphere = null, this.drawRange = { start: 0, count: 1 / 0 }, this.userData = {};
  }
  getIndex() {
    return this.index;
  }
  setIndex(e) {
    return Array.isArray(e) ? this.index = new (Io(e) ? zo : Go)(e, 1) : this.index = e, this;
  }
  setIndirect(e) {
    return this.indirect = e, this;
  }
  getIndirect() {
    return this.indirect;
  }
  getAttribute(e) {
    return this.attributes[e];
  }
  setAttribute(e, t) {
    return this.attributes[e] = t, this;
  }
  deleteAttribute(e) {
    return delete this.attributes[e], this;
  }
  hasAttribute(e) {
    return this.attributes[e] !== void 0;
  }
  addGroup(e, t, r = 0) {
    this.groups.push({
      start: e,
      count: t,
      materialIndex: r
    });
  }
  clearGroups() {
    this.groups = [];
  }
  setDrawRange(e, t) {
    this.drawRange.start = e, this.drawRange.count = t;
  }
  applyMatrix4(e) {
    const t = this.attributes.position;
    t !== void 0 && (t.applyMatrix4(e), t.needsUpdate = !0);
    const r = this.attributes.normal;
    if (r !== void 0) {
      const i = new Ye().getNormalMatrix(e);
      r.applyNormalMatrix(i), r.needsUpdate = !0;
    }
    const n = this.attributes.tangent;
    return n !== void 0 && (n.transformDirection(e), n.needsUpdate = !0), this.boundingBox !== null && this.computeBoundingBox(), this.boundingSphere !== null && this.computeBoundingSphere(), this;
  }
  applyQuaternion(e) {
    return Wt.makeRotationFromQuaternion(e), this.applyMatrix4(Wt), this;
  }
  rotateX(e) {
    return Wt.makeRotationX(e), this.applyMatrix4(Wt), this;
  }
  rotateY(e) {
    return Wt.makeRotationY(e), this.applyMatrix4(Wt), this;
  }
  rotateZ(e) {
    return Wt.makeRotationZ(e), this.applyMatrix4(Wt), this;
  }
  translate(e, t, r) {
    return Wt.makeTranslation(e, t, r), this.applyMatrix4(Wt), this;
  }
  scale(e, t, r) {
    return Wt.makeScale(e, t, r), this.applyMatrix4(Wt), this;
  }
  lookAt(e) {
    return ya.lookAt(e), ya.updateMatrix(), this.applyMatrix4(ya.matrix), this;
  }
  center() {
    return this.computeBoundingBox(), this.boundingBox.getCenter(ti).negate(), this.translate(ti.x, ti.y, ti.z), this;
  }
  setFromPoints(e) {
    const t = this.getAttribute("position");
    if (t === void 0) {
      const r = [];
      for (let n = 0, i = e.length; n < i; n++) {
        const s = e[n];
        r.push(s.x, s.y, s.z || 0);
      }
      this.setAttribute("position", new tn(r, 3));
    } else {
      for (let r = 0, n = t.count; r < n; r++) {
        const i = e[r];
        t.setXYZ(r, i.x, i.y, i.z || 0);
      }
      e.length > t.count && console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."), t.needsUpdate = !0;
    }
    return this;
  }
  computeBoundingBox() {
    this.boundingBox === null && (this.boundingBox = new An());
    const e = this.attributes.position, t = this.morphAttributes.position;
    if (e && e.isGLBufferAttribute) {
      console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.", this), this.boundingBox.set(
        new j(-1 / 0, -1 / 0, -1 / 0),
        new j(1 / 0, 1 / 0, 1 / 0)
      );
      return;
    }
    if (e !== void 0) {
      if (this.boundingBox.setFromBufferAttribute(e), t)
        for (let r = 0, n = t.length; r < n; r++) {
          const i = t[r];
          Vt.setFromBufferAttribute(i), this.morphTargetsRelative ? (mt.addVectors(this.boundingBox.min, Vt.min), this.boundingBox.expandByPoint(mt), mt.addVectors(this.boundingBox.max, Vt.max), this.boundingBox.expandByPoint(mt)) : (this.boundingBox.expandByPoint(Vt.min), this.boundingBox.expandByPoint(Vt.max));
        }
    } else
      this.boundingBox.makeEmpty();
    (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) && console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  }
  computeBoundingSphere() {
    this.boundingSphere === null && (this.boundingSphere = new gi());
    const e = this.attributes.position, t = this.morphAttributes.position;
    if (e && e.isGLBufferAttribute) {
      console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.", this), this.boundingSphere.set(new j(), 1 / 0);
      return;
    }
    if (e) {
      const r = this.boundingSphere.center;
      if (Vt.setFromBufferAttribute(e), t)
        for (let i = 0, s = t.length; i < s; i++) {
          const o = t[i];
          Li.setFromBufferAttribute(o), this.morphTargetsRelative ? (mt.addVectors(Vt.min, Li.min), Vt.expandByPoint(mt), mt.addVectors(Vt.max, Li.max), Vt.expandByPoint(mt)) : (Vt.expandByPoint(Li.min), Vt.expandByPoint(Li.max));
        }
      Vt.getCenter(r);
      let n = 0;
      for (let i = 0, s = e.count; i < s; i++)
        mt.fromBufferAttribute(e, i), n = Math.max(n, r.distanceToSquared(mt));
      if (t)
        for (let i = 0, s = t.length; i < s; i++) {
          const o = t[i], l = this.morphTargetsRelative;
          for (let c = 0, u = o.count; c < u; c++)
            mt.fromBufferAttribute(o, c), l && (ti.fromBufferAttribute(e, c), mt.add(ti)), n = Math.max(n, r.distanceToSquared(mt));
        }
      this.boundingSphere.radius = Math.sqrt(n), isNaN(this.boundingSphere.radius) && console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
    }
  }
  computeTangents() {
    const e = this.index, t = this.attributes;
    if (e === null || t.position === void 0 || t.normal === void 0 || t.uv === void 0) {
      console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");
      return;
    }
    const r = t.position, n = t.normal, i = t.uv;
    this.hasAttribute("tangent") === !1 && this.setAttribute("tangent", new en(new Float32Array(4 * r.count), 4));
    const s = this.getAttribute("tangent"), o = [], l = [];
    for (let R = 0; R < r.count; R++)
      o[R] = new j(), l[R] = new j();
    const c = new j(), u = new j(), f = new j(), h = new Ce(), d = new Ce(), g = new Ce(), v = new j(), m = new j();
    function p(R, E, S) {
      c.fromBufferAttribute(r, R), u.fromBufferAttribute(r, E), f.fromBufferAttribute(r, S), h.fromBufferAttribute(i, R), d.fromBufferAttribute(i, E), g.fromBufferAttribute(i, S), u.sub(c), f.sub(c), d.sub(h), g.sub(h);
      const F = 1 / (d.x * g.y - g.x * d.y);
      isFinite(F) && (v.copy(u).multiplyScalar(g.y).addScaledVector(f, -d.y).multiplyScalar(F), m.copy(f).multiplyScalar(d.x).addScaledVector(u, -g.x).multiplyScalar(F), o[R].add(v), o[E].add(v), o[S].add(v), l[R].add(m), l[E].add(m), l[S].add(m));
    }
    let T = this.groups;
    T.length === 0 && (T = [{
      start: 0,
      count: e.count
    }]);
    for (let R = 0, E = T.length; R < E; ++R) {
      const S = T[R], F = S.start, L = S.count;
      for (let B = F, k = F + L; B < k; B += 3)
        p(
          e.getX(B + 0),
          e.getX(B + 1),
          e.getX(B + 2)
        );
    }
    const x = new j(), _ = new j(), D = new j(), C = new j();
    function A(R) {
      D.fromBufferAttribute(n, R), C.copy(D);
      const E = o[R];
      x.copy(E), x.sub(D.multiplyScalar(D.dot(E))).normalize(), _.crossVectors(C, E);
      const F = _.dot(l[R]) < 0 ? -1 : 1;
      s.setXYZW(R, x.x, x.y, x.z, F);
    }
    for (let R = 0, E = T.length; R < E; ++R) {
      const S = T[R], F = S.start, L = S.count;
      for (let B = F, k = F + L; B < k; B += 3)
        A(e.getX(B + 0)), A(e.getX(B + 1)), A(e.getX(B + 2));
    }
  }
  computeVertexNormals() {
    const e = this.index, t = this.getAttribute("position");
    if (t !== void 0) {
      let r = this.getAttribute("normal");
      if (r === void 0)
        r = new en(new Float32Array(t.count * 3), 3), this.setAttribute("normal", r);
      else
        for (let h = 0, d = r.count; h < d; h++)
          r.setXYZ(h, 0, 0, 0);
      const n = new j(), i = new j(), s = new j(), o = new j(), l = new j(), c = new j(), u = new j(), f = new j();
      if (e)
        for (let h = 0, d = e.count; h < d; h += 3) {
          const g = e.getX(h + 0), v = e.getX(h + 1), m = e.getX(h + 2);
          n.fromBufferAttribute(t, g), i.fromBufferAttribute(t, v), s.fromBufferAttribute(t, m), u.subVectors(s, i), f.subVectors(n, i), u.cross(f), o.fromBufferAttribute(r, g), l.fromBufferAttribute(r, v), c.fromBufferAttribute(r, m), o.add(u), l.add(u), c.add(u), r.setXYZ(g, o.x, o.y, o.z), r.setXYZ(v, l.x, l.y, l.z), r.setXYZ(m, c.x, c.y, c.z);
        }
      else
        for (let h = 0, d = t.count; h < d; h += 3)
          n.fromBufferAttribute(t, h + 0), i.fromBufferAttribute(t, h + 1), s.fromBufferAttribute(t, h + 2), u.subVectors(s, i), f.subVectors(n, i), u.cross(f), r.setXYZ(h + 0, u.x, u.y, u.z), r.setXYZ(h + 1, u.x, u.y, u.z), r.setXYZ(h + 2, u.x, u.y, u.z);
      this.normalizeNormals(), r.needsUpdate = !0;
    }
  }
  normalizeNormals() {
    const e = this.attributes.normal;
    for (let t = 0, r = e.count; t < r; t++)
      mt.fromBufferAttribute(e, t), mt.normalize(), e.setXYZ(t, mt.x, mt.y, mt.z);
  }
  toNonIndexed() {
    function e(o, l) {
      const c = o.array, u = o.itemSize, f = o.normalized, h = new c.constructor(l.length * u);
      let d = 0, g = 0;
      for (let v = 0, m = l.length; v < m; v++) {
        o.isInterleavedBufferAttribute ? d = l[v] * o.data.stride + o.offset : d = l[v] * u;
        for (let p = 0; p < u; p++)
          h[g++] = c[d++];
      }
      return new en(h, u, f);
    }
    if (this.index === null)
      return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."), this;
    const t = new St(), r = this.index.array, n = this.attributes;
    for (const o in n) {
      const l = n[o], c = e(l, r);
      t.setAttribute(o, c);
    }
    const i = this.morphAttributes;
    for (const o in i) {
      const l = [], c = i[o];
      for (let u = 0, f = c.length; u < f; u++) {
        const h = c[u], d = e(h, r);
        l.push(d);
      }
      t.morphAttributes[o] = l;
    }
    t.morphTargetsRelative = this.morphTargetsRelative;
    const s = this.groups;
    for (let o = 0, l = s.length; o < l; o++) {
      const c = s[o];
      t.addGroup(c.start, c.count, c.materialIndex);
    }
    return t;
  }
  toJSON() {
    const e = {
      metadata: {
        version: 4.6,
        type: "BufferGeometry",
        generator: "BufferGeometry.toJSON"
      }
    };
    if (e.uuid = this.uuid, e.type = this.type, this.name !== "" && (e.name = this.name), Object.keys(this.userData).length > 0 && (e.userData = this.userData), this.parameters !== void 0) {
      const l = this.parameters;
      for (const c in l)
        l[c] !== void 0 && (e[c] = l[c]);
      return e;
    }
    e.data = { attributes: {} };
    const t = this.index;
    t !== null && (e.data.index = {
      type: t.array.constructor.name,
      array: Array.prototype.slice.call(t.array)
    });
    const r = this.attributes;
    for (const l in r) {
      const c = r[l];
      e.data.attributes[l] = c.toJSON(e.data);
    }
    const n = {};
    let i = !1;
    for (const l in this.morphAttributes) {
      const c = this.morphAttributes[l], u = [];
      for (let f = 0, h = c.length; f < h; f++) {
        const d = c[f];
        u.push(d.toJSON(e.data));
      }
      u.length > 0 && (n[l] = u, i = !0);
    }
    i && (e.data.morphAttributes = n, e.data.morphTargetsRelative = this.morphTargetsRelative);
    const s = this.groups;
    s.length > 0 && (e.data.groups = JSON.parse(JSON.stringify(s)));
    const o = this.boundingSphere;
    return o !== null && (e.data.boundingSphere = {
      center: o.center.toArray(),
      radius: o.radius
    }), e;
  }
  clone() {
    return new this.constructor().copy(this);
  }
  copy(e) {
    this.index = null, this.attributes = {}, this.morphAttributes = {}, this.groups = [], this.boundingBox = null, this.boundingSphere = null;
    const t = {};
    this.name = e.name;
    const r = e.index;
    r !== null && this.setIndex(r.clone(t));
    const n = e.attributes;
    for (const c in n) {
      const u = n[c];
      this.setAttribute(c, u.clone(t));
    }
    const i = e.morphAttributes;
    for (const c in i) {
      const u = [], f = i[c];
      for (let h = 0, d = f.length; h < d; h++)
        u.push(f[h].clone(t));
      this.morphAttributes[c] = u;
    }
    this.morphTargetsRelative = e.morphTargetsRelative;
    const s = e.groups;
    for (let c = 0, u = s.length; c < u; c++) {
      const f = s[c];
      this.addGroup(f.start, f.count, f.materialIndex);
    }
    const o = e.boundingBox;
    o !== null && (this.boundingBox = o.clone());
    const l = e.boundingSphere;
    return l !== null && (this.boundingSphere = l.clone()), this.drawRange.start = e.drawRange.start, this.drawRange.count = e.drawRange.count, this.userData = e.userData, this;
  }
  dispose() {
    this.dispatchEvent({ type: "dispose" });
  }
}
const Fs = /* @__PURE__ */ new st(), Rn = /* @__PURE__ */ new Ja(), ur = /* @__PURE__ */ new gi(), Is = /* @__PURE__ */ new j(), hr = /* @__PURE__ */ new j(), fr = /* @__PURE__ */ new j(), dr = /* @__PURE__ */ new j(), Ma = /* @__PURE__ */ new j(), pr = /* @__PURE__ */ new j(), Ns = /* @__PURE__ */ new j(), mr = /* @__PURE__ */ new j();
class Nt extends gt {
  constructor(e = new St(), t = new Vi()) {
    super(), this.isMesh = !0, this.type = "Mesh", this.geometry = e, this.material = t, this.updateMorphTargets();
  }
  copy(e, t) {
    return super.copy(e, t), e.morphTargetInfluences !== void 0 && (this.morphTargetInfluences = e.morphTargetInfluences.slice()), e.morphTargetDictionary !== void 0 && (this.morphTargetDictionary = Object.assign({}, e.morphTargetDictionary)), this.material = Array.isArray(e.material) ? e.material.slice() : e.material, this.geometry = e.geometry, this;
  }
  updateMorphTargets() {
    const t = this.geometry.morphAttributes, r = Object.keys(t);
    if (r.length > 0) {
      const n = t[r[0]];
      if (n !== void 0) {
        this.morphTargetInfluences = [], this.morphTargetDictionary = {};
        for (let i = 0, s = n.length; i < s; i++) {
          const o = n[i].name || String(i);
          this.morphTargetInfluences.push(0), this.morphTargetDictionary[o] = i;
        }
      }
    }
  }
  getVertexPosition(e, t) {
    const r = this.geometry, n = r.attributes.position, i = r.morphAttributes.position, s = r.morphTargetsRelative;
    t.fromBufferAttribute(n, e);
    const o = this.morphTargetInfluences;
    if (i && o) {
      pr.set(0, 0, 0);
      for (let l = 0, c = i.length; l < c; l++) {
        const u = o[l], f = i[l];
        u !== 0 && (Ma.fromBufferAttribute(f, e), s ? pr.addScaledVector(Ma, u) : pr.addScaledVector(Ma.sub(t), u));
      }
      t.add(pr);
    }
    return t;
  }
  raycast(e, t) {
    const r = this.geometry, n = this.material, i = this.matrixWorld;
    n !== void 0 && (r.boundingSphere === null && r.computeBoundingSphere(), ur.copy(r.boundingSphere), ur.applyMatrix4(i), Rn.copy(e.ray).recast(e.near), !(ur.containsPoint(Rn.origin) === !1 && (Rn.intersectSphere(ur, Is) === null || Rn.origin.distanceToSquared(Is) > (e.far - e.near) ** 2)) && (Fs.copy(i).invert(), Rn.copy(e.ray).applyMatrix4(Fs), !(r.boundingBox !== null && Rn.intersectsBox(r.boundingBox) === !1) && this._computeIntersections(e, t, Rn)));
  }
  _computeIntersections(e, t, r) {
    let n;
    const i = this.geometry, s = this.material, o = i.index, l = i.attributes.position, c = i.attributes.uv, u = i.attributes.uv1, f = i.attributes.normal, h = i.groups, d = i.drawRange;
    if (o !== null)
      if (Array.isArray(s))
        for (let g = 0, v = h.length; g < v; g++) {
          const m = h[g], p = s[m.materialIndex], T = Math.max(m.start, d.start), x = Math.min(o.count, Math.min(m.start + m.count, d.start + d.count));
          for (let _ = T, D = x; _ < D; _ += 3) {
            const C = o.getX(_), A = o.getX(_ + 1), R = o.getX(_ + 2);
            n = gr(this, p, e, r, c, u, f, C, A, R), n && (n.faceIndex = Math.floor(_ / 3), n.face.materialIndex = m.materialIndex, t.push(n));
          }
        }
      else {
        const g = Math.max(0, d.start), v = Math.min(o.count, d.start + d.count);
        for (let m = g, p = v; m < p; m += 3) {
          const T = o.getX(m), x = o.getX(m + 1), _ = o.getX(m + 2);
          n = gr(this, s, e, r, c, u, f, T, x, _), n && (n.faceIndex = Math.floor(m / 3), t.push(n));
        }
      }
    else if (l !== void 0)
      if (Array.isArray(s))
        for (let g = 0, v = h.length; g < v; g++) {
          const m = h[g], p = s[m.materialIndex], T = Math.max(m.start, d.start), x = Math.min(l.count, Math.min(m.start + m.count, d.start + d.count));
          for (let _ = T, D = x; _ < D; _ += 3) {
            const C = _, A = _ + 1, R = _ + 2;
            n = gr(this, p, e, r, c, u, f, C, A, R), n && (n.faceIndex = Math.floor(_ / 3), n.face.materialIndex = m.materialIndex, t.push(n));
          }
        }
      else {
        const g = Math.max(0, d.start), v = Math.min(l.count, d.start + d.count);
        for (let m = g, p = v; m < p; m += 3) {
          const T = m, x = m + 1, _ = m + 2;
          n = gr(this, s, e, r, c, u, f, T, x, _), n && (n.faceIndex = Math.floor(m / 3), t.push(n));
        }
      }
  }
}
function Hl(a, e, t, r, n, i, s, o) {
  let l;
  if (e.side === 1 ? l = r.intersectTriangle(s, i, n, !0, o) : l = r.intersectTriangle(n, i, s, e.side === 0, o), l === null) return null;
  mr.copy(o), mr.applyMatrix4(a.matrixWorld);
  const c = t.ray.origin.distanceTo(mr);
  return c < t.near || c > t.far ? null : {
    distance: c,
    point: mr.clone(),
    object: a
  };
}
function gr(a, e, t, r, n, i, s, o, l, c) {
  a.getVertexPosition(o, hr), a.getVertexPosition(l, fr), a.getVertexPosition(c, dr);
  const u = Hl(a, e, t, r, hr, fr, dr, Ns);
  if (u) {
    const f = new j();
    $t.getBarycoord(Ns, hr, fr, dr, f), n && (u.uv = $t.getInterpolatedAttribute(n, o, l, c, f, new Ce())), i && (u.uv1 = $t.getInterpolatedAttribute(i, o, l, c, f, new Ce())), s && (u.normal = $t.getInterpolatedAttribute(s, o, l, c, f, new j()), u.normal.dot(r.direction) > 0 && u.normal.multiplyScalar(-1));
    const h = {
      a: o,
      b: l,
      c,
      normal: new j(),
      materialIndex: 0
    };
    $t.getNormal(hr, fr, dr, h.normal), u.face = h, u.barycoord = f;
  }
  return u;
}
class Yi extends St {
  constructor(e = 1, t = 1, r = 1, n = 1, i = 1, s = 1) {
    super(), this.type = "BoxGeometry", this.parameters = {
      width: e,
      height: t,
      depth: r,
      widthSegments: n,
      heightSegments: i,
      depthSegments: s
    };
    const o = this;
    n = Math.floor(n), i = Math.floor(i), s = Math.floor(s);
    const l = [], c = [], u = [], f = [];
    let h = 0, d = 0;
    g("z", "y", "x", -1, -1, r, t, e, s, i, 0), g("z", "y", "x", 1, -1, r, t, -e, s, i, 1), g("x", "z", "y", 1, 1, e, r, t, n, s, 2), g("x", "z", "y", 1, -1, e, r, -t, n, s, 3), g("x", "y", "z", 1, -1, e, t, r, n, i, 4), g("x", "y", "z", -1, -1, e, t, -r, n, i, 5), this.setIndex(l), this.setAttribute("position", new tn(c, 3)), this.setAttribute("normal", new tn(u, 3)), this.setAttribute("uv", new tn(f, 2));
    function g(v, m, p, T, x, _, D, C, A, R, E) {
      const S = _ / A, F = D / R, L = _ / 2, B = D / 2, k = C / 2, O = A + 1, z = R + 1;
      let ne = 0, q = 0;
      const K = new j();
      for (let Z = 0; Z < z; Z++) {
        const N = Z * F - B;
        for (let Y = 0; Y < O; Y++) {
          const ie = Y * S - L;
          K[v] = ie * T, K[m] = N * x, K[p] = k, c.push(K.x, K.y, K.z), K[v] = 0, K[m] = 0, K[p] = C > 0 ? 1 : -1, u.push(K.x, K.y, K.z), f.push(Y / A), f.push(1 - Z / R), ne += 1;
        }
      }
      for (let Z = 0; Z < R; Z++)
        for (let N = 0; N < A; N++) {
          const Y = h + N + O * Z, ie = h + N + O * (Z + 1), b = h + (N + 1) + O * (Z + 1), U = h + (N + 1) + O * Z;
          l.push(Y, ie, U), l.push(ie, b, U), q += 6;
        }
      o.addGroup(d, q, E), d += q, h += ne;
    }
  }
  copy(e) {
    return super.copy(e), this.parameters = Object.assign({}, e.parameters), this;
  }
  static fromJSON(e) {
    return new Yi(e.width, e.height, e.depth, e.widthSegments, e.heightSegments, e.depthSegments);
  }
}
function di(a) {
  const e = {};
  for (const t in a) {
    e[t] = {};
    for (const r in a[t]) {
      const n = a[t][r];
      n && (n.isColor || n.isMatrix3 || n.isMatrix4 || n.isVector2 || n.isVector3 || n.isVector4 || n.isTexture || n.isQuaternion) ? n.isRenderTargetTexture ? (console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."), e[t][r] = null) : e[t][r] = n.clone() : Array.isArray(n) ? e[t][r] = n.slice() : e[t][r] = n;
    }
  }
  return e;
}
function At(a) {
  const e = {};
  for (let t = 0; t < a.length; t++) {
    const r = di(a[t]);
    for (const n in r)
      e[n] = r[n];
  }
  return e;
}
function Wl(a) {
  const e = [];
  for (let t = 0; t < a.length; t++)
    e.push(a[t].clone());
  return e;
}
function Vo(a) {
  const e = a.getRenderTarget();
  return e === null ? a.outputColorSpace : e.isXRRenderTarget === !0 ? e.texture.colorSpace : $e.workingColorSpace;
}
const Qa = { clone: di, merge: At };
var Xl = `void main() {
	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`, ql = `void main() {
	gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
}`;
class bn extends vi {
  static get type() {
    return "ShaderMaterial";
  }
  constructor(e) {
    super(), this.isShaderMaterial = !0, this.defines = {}, this.uniforms = {}, this.uniformsGroups = [], this.vertexShader = Xl, this.fragmentShader = ql, this.linewidth = 1, this.wireframe = !1, this.wireframeLinewidth = 1, this.fog = !1, this.lights = !1, this.clipping = !1, this.forceSinglePass = !0, this.extensions = {
      clipCullDistance: !1,
      // set to use vertex shader clipping
      multiDraw: !1
      // set to use vertex shader multi_draw / enable gl_DrawID
    }, this.defaultAttributeValues = {
      color: [1, 1, 1],
      uv: [0, 0],
      uv1: [0, 0]
    }, this.index0AttributeName = void 0, this.uniformsNeedUpdate = !1, this.glslVersion = null, e !== void 0 && this.setValues(e);
  }
  copy(e) {
    return super.copy(e), this.fragmentShader = e.fragmentShader, this.vertexShader = e.vertexShader, this.uniforms = di(e.uniforms), this.uniformsGroups = Wl(e.uniformsGroups), this.defines = Object.assign({}, e.defines), this.wireframe = e.wireframe, this.wireframeLinewidth = e.wireframeLinewidth, this.fog = e.fog, this.lights = e.lights, this.clipping = e.clipping, this.extensions = Object.assign({}, e.extensions), this.glslVersion = e.glslVersion, this;
  }
  toJSON(e) {
    const t = super.toJSON(e);
    t.glslVersion = this.glslVersion, t.uniforms = {};
    for (const n in this.uniforms) {
      const s = this.uniforms[n].value;
      s && s.isTexture ? t.uniforms[n] = {
        type: "t",
        value: s.toJSON(e).uuid
      } : s && s.isColor ? t.uniforms[n] = {
        type: "c",
        value: s.getHex()
      } : s && s.isVector2 ? t.uniforms[n] = {
        type: "v2",
        value: s.toArray()
      } : s && s.isVector3 ? t.uniforms[n] = {
        type: "v3",
        value: s.toArray()
      } : s && s.isVector4 ? t.uniforms[n] = {
        type: "v4",
        value: s.toArray()
      } : s && s.isMatrix3 ? t.uniforms[n] = {
        type: "m3",
        value: s.toArray()
      } : s && s.isMatrix4 ? t.uniforms[n] = {
        type: "m4",
        value: s.toArray()
      } : t.uniforms[n] = {
        value: s
      };
    }
    Object.keys(this.defines).length > 0 && (t.defines = this.defines), t.vertexShader = this.vertexShader, t.fragmentShader = this.fragmentShader, t.lights = this.lights, t.clipping = this.clipping;
    const r = {};
    for (const n in this.extensions)
      this.extensions[n] === !0 && (r[n] = !0);
    return Object.keys(r).length > 0 && (t.extensions = r), t;
  }
}
class Ho extends gt {
  constructor() {
    super(), this.isCamera = !0, this.type = "Camera", this.matrixWorldInverse = new st(), this.projectionMatrix = new st(), this.projectionMatrixInverse = new st(), this.coordinateSystem = 2e3;
  }
  copy(e, t) {
    return super.copy(e, t), this.matrixWorldInverse.copy(e.matrixWorldInverse), this.projectionMatrix.copy(e.projectionMatrix), this.projectionMatrixInverse.copy(e.projectionMatrixInverse), this.coordinateSystem = e.coordinateSystem, this;
  }
  getWorldDirection(e) {
    return super.getWorldDirection(e).negate();
  }
  updateMatrixWorld(e) {
    super.updateMatrixWorld(e), this.matrixWorldInverse.copy(this.matrixWorld).invert();
  }
  updateWorldMatrix(e, t) {
    super.updateWorldMatrix(e, t), this.matrixWorldInverse.copy(this.matrixWorld).invert();
  }
  clone() {
    return new this.constructor().copy(this);
  }
}
const En = /* @__PURE__ */ new j(), Os = /* @__PURE__ */ new Ce(), Bs = /* @__PURE__ */ new Ce();
class Qt extends Ho {
  constructor(e = 50, t = 1, r = 0.1, n = 2e3) {
    super(), this.isPerspectiveCamera = !0, this.type = "PerspectiveCamera", this.fov = e, this.zoom = 1, this.near = r, this.far = n, this.focus = 10, this.aspect = t, this.view = null, this.filmGauge = 35, this.filmOffset = 0, this.updateProjectionMatrix();
  }
  copy(e, t) {
    return super.copy(e, t), this.fov = e.fov, this.zoom = e.zoom, this.near = e.near, this.far = e.far, this.focus = e.focus, this.aspect = e.aspect, this.view = e.view === null ? null : Object.assign({}, e.view), this.filmGauge = e.filmGauge, this.filmOffset = e.filmOffset, this;
  }
  /**
   * Sets the FOV by focal length in respect to the current .filmGauge.
   *
   * The default film gauge is 35, so that the focal length can be specified for
   * a 35mm (full frame) camera.
   *
   * Values for focal length and film gauge must have the same unit.
   */
  setFocalLength(e) {
    const t = 0.5 * this.getFilmHeight() / e;
    this.fov = ka * 2 * Math.atan(t), this.updateProjectionMatrix();
  }
  /**
   * Calculates the focal length from the current .fov and .filmGauge.
   */
  getFocalLength() {
    const e = Math.tan(na * 0.5 * this.fov);
    return 0.5 * this.getFilmHeight() / e;
  }
  getEffectiveFOV() {
    return ka * 2 * Math.atan(
      Math.tan(na * 0.5 * this.fov) / this.zoom
    );
  }
  getFilmWidth() {
    return this.filmGauge * Math.min(this.aspect, 1);
  }
  getFilmHeight() {
    return this.filmGauge / Math.max(this.aspect, 1);
  }
  /**
   * Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
   * Sets minTarget and maxTarget to the coordinates of the lower-left and upper-right corners of the view rectangle.
   */
  getViewBounds(e, t, r) {
    En.set(-1, -1, 0.5).applyMatrix4(this.projectionMatrixInverse), t.set(En.x, En.y).multiplyScalar(-e / En.z), En.set(1, 1, 0.5).applyMatrix4(this.projectionMatrixInverse), r.set(En.x, En.y).multiplyScalar(-e / En.z);
  }
  /**
   * Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.
   * Copies the result into the target Vector2, where x is width and y is height.
   */
  getViewSize(e, t) {
    return this.getViewBounds(e, Os, Bs), t.subVectors(Bs, Os);
  }
  /**
   * Sets an offset in a larger frustum. This is useful for multi-window or
   * multi-monitor/multi-machine setups.
   *
   * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
   * the monitors are in grid like this
   *
   *   +---+---+---+
   *   | A | B | C |
   *   +---+---+---+
   *   | D | E | F |
   *   +---+---+---+
   *
   * then for each monitor you would call it like this
   *
   *   const w = 1920;
   *   const h = 1080;
   *   const fullWidth = w * 3;
   *   const fullHeight = h * 2;
   *
   *   --A--
   *   camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
   *   --B--
   *   camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
   *   --C--
   *   camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
   *   --D--
   *   camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
   *   --E--
   *   camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
   *   --F--
   *   camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
   *
   *   Note there is no reason monitors have to be the same size or in a grid.
   */
  setViewOffset(e, t, r, n, i, s) {
    this.aspect = e / t, this.view === null && (this.view = {
      enabled: !0,
      fullWidth: 1,
      fullHeight: 1,
      offsetX: 0,
      offsetY: 0,
      width: 1,
      height: 1
    }), this.view.enabled = !0, this.view.fullWidth = e, this.view.fullHeight = t, this.view.offsetX = r, this.view.offsetY = n, this.view.width = i, this.view.height = s, this.updateProjectionMatrix();
  }
  clearViewOffset() {
    this.view !== null && (this.view.enabled = !1), this.updateProjectionMatrix();
  }
  updateProjectionMatrix() {
    const e = this.near;
    let t = e * Math.tan(na * 0.5 * this.fov) / this.zoom, r = 2 * t, n = this.aspect * r, i = -0.5 * n;
    const s = this.view;
    if (this.view !== null && this.view.enabled) {
      const l = s.fullWidth, c = s.fullHeight;
      i += s.offsetX * n / l, t -= s.offsetY * r / c, n *= s.width / l, r *= s.height / c;
    }
    const o = this.filmOffset;
    o !== 0 && (i += e * o / this.getFilmWidth()), this.projectionMatrix.makePerspective(i, i + n, t, t - r, e, this.far, this.coordinateSystem), this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  }
  toJSON(e) {
    const t = super.toJSON(e);
    return t.object.fov = this.fov, t.object.zoom = this.zoom, t.object.near = this.near, t.object.far = this.far, t.object.focus = this.focus, t.object.aspect = this.aspect, this.view !== null && (t.object.view = Object.assign({}, this.view)), t.object.filmGauge = this.filmGauge, t.object.filmOffset = this.filmOffset, t;
  }
}
const ni = -90, ii = 1;
class Yl extends gt {
  constructor(e, t, r) {
    super(), this.type = "CubeCamera", this.renderTarget = r, this.coordinateSystem = null, this.activeMipmapLevel = 0;
    const n = new Qt(ni, ii, e, t);
    n.layers = this.layers, this.add(n);
    const i = new Qt(ni, ii, e, t);
    i.layers = this.layers, this.add(i);
    const s = new Qt(ni, ii, e, t);
    s.layers = this.layers, this.add(s);
    const o = new Qt(ni, ii, e, t);
    o.layers = this.layers, this.add(o);
    const l = new Qt(ni, ii, e, t);
    l.layers = this.layers, this.add(l);
    const c = new Qt(ni, ii, e, t);
    c.layers = this.layers, this.add(c);
  }
  updateCoordinateSystem() {
    const e = this.coordinateSystem, t = this.children.concat(), [r, n, i, s, o, l] = t;
    for (const c of t) this.remove(c);
    if (e === 2e3)
      r.up.set(0, 1, 0), r.lookAt(1, 0, 0), n.up.set(0, 1, 0), n.lookAt(-1, 0, 0), i.up.set(0, 0, -1), i.lookAt(0, 1, 0), s.up.set(0, 0, 1), s.lookAt(0, -1, 0), o.up.set(0, 1, 0), o.lookAt(0, 0, 1), l.up.set(0, 1, 0), l.lookAt(0, 0, -1);
    else if (e === 2001)
      r.up.set(0, -1, 0), r.lookAt(-1, 0, 0), n.up.set(0, -1, 0), n.lookAt(1, 0, 0), i.up.set(0, 0, 1), i.lookAt(0, 1, 0), s.up.set(0, 0, -1), s.lookAt(0, -1, 0), o.up.set(0, -1, 0), o.lookAt(0, 0, 1), l.up.set(0, -1, 0), l.lookAt(0, 0, -1);
    else
      throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: " + e);
    for (const c of t)
      this.add(c), c.updateMatrixWorld();
  }
  update(e, t) {
    this.parent === null && this.updateMatrixWorld();
    const { renderTarget: r, activeMipmapLevel: n } = this;
    this.coordinateSystem !== e.coordinateSystem && (this.coordinateSystem = e.coordinateSystem, this.updateCoordinateSystem());
    const [i, s, o, l, c, u] = this.children, f = e.getRenderTarget(), h = e.getActiveCubeFace(), d = e.getActiveMipmapLevel(), g = e.xr.enabled;
    e.xr.enabled = !1;
    const v = r.texture.generateMipmaps;
    r.texture.generateMipmaps = !1, e.setRenderTarget(r, 0, n), e.render(t, i), e.setRenderTarget(r, 1, n), e.render(t, s), e.setRenderTarget(r, 2, n), e.render(t, o), e.setRenderTarget(r, 3, n), e.render(t, l), e.setRenderTarget(r, 4, n), e.render(t, c), r.texture.generateMipmaps = v, e.setRenderTarget(r, 5, n), e.render(t, u), e.setRenderTarget(f, h, d), e.xr.enabled = g, r.texture.needsPMREMUpdate = !0;
  }
}
class Wo extends wt {
  constructor(e, t, r, n, i, s, o, l, c, u) {
    e = e !== void 0 ? e : [], t = t !== void 0 ? t : 301, super(e, t, r, n, i, s, o, l, c, u), this.isCubeTexture = !0, this.flipY = !1;
  }
  get images() {
    return this.image;
  }
  set images(e) {
    this.image = e;
  }
}
class jl extends Bn {
  constructor(e = 1, t = {}) {
    super(e, e, t), this.isWebGLCubeRenderTarget = !0;
    const r = { width: e, height: e, depth: 1 }, n = [r, r, r, r, r, r];
    this.texture = new Wo(n, t.mapping, t.wrapS, t.wrapT, t.magFilter, t.minFilter, t.format, t.type, t.anisotropy, t.colorSpace), this.texture.isRenderTargetTexture = !0, this.texture.generateMipmaps = t.generateMipmaps !== void 0 ? t.generateMipmaps : !1, this.texture.minFilter = t.minFilter !== void 0 ? t.minFilter : 1006;
  }
  fromEquirectangularTexture(e, t) {
    this.texture.type = t.type, this.texture.colorSpace = t.colorSpace, this.texture.generateMipmaps = t.generateMipmaps, this.texture.minFilter = t.minFilter, this.texture.magFilter = t.magFilter;
    const r = {
      uniforms: {
        tEquirect: { value: null }
      },
      vertexShader: (
        /* glsl */
        `

				varying vec3 vWorldDirection;

				vec3 transformDirection( in vec3 dir, in mat4 matrix ) {

					return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );

				}

				void main() {

					vWorldDirection = transformDirection( position, modelMatrix );

					#include <begin_vertex>
					#include <project_vertex>

				}
			`
      ),
      fragmentShader: (
        /* glsl */
        `

				uniform sampler2D tEquirect;

				varying vec3 vWorldDirection;

				#include <common>

				void main() {

					vec3 direction = normalize( vWorldDirection );

					vec2 sampleUV = equirectUv( direction );

					gl_FragColor = texture2D( tEquirect, sampleUV );

				}
			`
      )
    }, n = new Yi(5, 5, 5), i = new bn({
      name: "CubemapFromEquirect",
      uniforms: di(r.uniforms),
      vertexShader: r.vertexShader,
      fragmentShader: r.fragmentShader,
      side: 1,
      blending: 0
    });
    i.uniforms.tEquirect.value = t;
    const s = new Nt(n, i), o = t.minFilter;
    return t.minFilter === 1008 && (t.minFilter = 1006), new Yl(1, 10, this).update(e, s), t.minFilter = o, s.geometry.dispose(), s.material.dispose(), this;
  }
  clear(e, t, r, n) {
    const i = e.getRenderTarget();
    for (let s = 0; s < 6; s++)
      e.setRenderTarget(this, s), e.clear(t, r, n);
    e.setRenderTarget(i);
  }
}
const Ea = /* @__PURE__ */ new j(), Zl = /* @__PURE__ */ new j(), Kl = /* @__PURE__ */ new Ye();
class Fn {
  constructor(e = new j(1, 0, 0), t = 0) {
    this.isPlane = !0, this.normal = e, this.constant = t;
  }
  set(e, t) {
    return this.normal.copy(e), this.constant = t, this;
  }
  setComponents(e, t, r, n) {
    return this.normal.set(e, t, r), this.constant = n, this;
  }
  setFromNormalAndCoplanarPoint(e, t) {
    return this.normal.copy(e), this.constant = -t.dot(this.normal), this;
  }
  setFromCoplanarPoints(e, t, r) {
    const n = Ea.subVectors(r, t).cross(Zl.subVectors(e, t)).normalize();
    return this.setFromNormalAndCoplanarPoint(n, e), this;
  }
  copy(e) {
    return this.normal.copy(e.normal), this.constant = e.constant, this;
  }
  normalize() {
    const e = 1 / this.normal.length();
    return this.normal.multiplyScalar(e), this.constant *= e, this;
  }
  negate() {
    return this.constant *= -1, this.normal.negate(), this;
  }
  distanceToPoint(e) {
    return this.normal.dot(e) + this.constant;
  }
  distanceToSphere(e) {
    return this.distanceToPoint(e.center) - e.radius;
  }
  projectPoint(e, t) {
    return t.copy(e).addScaledVector(this.normal, -this.distanceToPoint(e));
  }
  intersectLine(e, t) {
    const r = e.delta(Ea), n = this.normal.dot(r);
    if (n === 0)
      return this.distanceToPoint(e.start) === 0 ? t.copy(e.start) : null;
    const i = -(e.start.dot(this.normal) + this.constant) / n;
    return i < 0 || i > 1 ? null : t.copy(e.start).addScaledVector(r, i);
  }
  intersectsLine(e) {
    const t = this.distanceToPoint(e.start), r = this.distanceToPoint(e.end);
    return t < 0 && r > 0 || r < 0 && t > 0;
  }
  intersectsBox(e) {
    return e.intersectsPlane(this);
  }
  intersectsSphere(e) {
    return e.intersectsPlane(this);
  }
  coplanarPoint(e) {
    return e.copy(this.normal).multiplyScalar(-this.constant);
  }
  applyMatrix4(e, t) {
    const r = t || Kl.getNormalMatrix(e), n = this.coplanarPoint(Ea).applyMatrix4(e), i = this.normal.applyMatrix3(r).normalize();
    return this.constant = -n.dot(i), this;
  }
  translate(e) {
    return this.constant -= e.dot(this.normal), this;
  }
  equals(e) {
    return e.normal.equals(this.normal) && e.constant === this.constant;
  }
  clone() {
    return new this.constructor().copy(this);
  }
}
const Pn = /* @__PURE__ */ new gi(), vr = /* @__PURE__ */ new j();
class Xo {
  constructor(e = new Fn(), t = new Fn(), r = new Fn(), n = new Fn(), i = new Fn(), s = new Fn()) {
    this.planes = [e, t, r, n, i, s];
  }
  set(e, t, r, n, i, s) {
    const o = this.planes;
    return o[0].copy(e), o[1].copy(t), o[2].copy(r), o[3].copy(n), o[4].copy(i), o[5].copy(s), this;
  }
  copy(e) {
    const t = this.planes;
    for (let r = 0; r < 6; r++)
      t[r].copy(e.planes[r]);
    return this;
  }
  setFromProjectionMatrix(e, t = 2e3) {
    const r = this.planes, n = e.elements, i = n[0], s = n[1], o = n[2], l = n[3], c = n[4], u = n[5], f = n[6], h = n[7], d = n[8], g = n[9], v = n[10], m = n[11], p = n[12], T = n[13], x = n[14], _ = n[15];
    if (r[0].setComponents(l - i, h - c, m - d, _ - p).normalize(), r[1].setComponents(l + i, h + c, m + d, _ + p).normalize(), r[2].setComponents(l + s, h + u, m + g, _ + T).normalize(), r[3].setComponents(l - s, h - u, m - g, _ - T).normalize(), r[4].setComponents(l - o, h - f, m - v, _ - x).normalize(), t === 2e3)
      r[5].setComponents(l + o, h + f, m + v, _ + x).normalize();
    else if (t === 2001)
      r[5].setComponents(o, f, v, x).normalize();
    else
      throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: " + t);
    return this;
  }
  intersectsObject(e) {
    if (e.boundingSphere !== void 0)
      e.boundingSphere === null && e.computeBoundingSphere(), Pn.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);
    else {
      const t = e.geometry;
      t.boundingSphere === null && t.computeBoundingSphere(), Pn.copy(t.boundingSphere).applyMatrix4(e.matrixWorld);
    }
    return this.intersectsSphere(Pn);
  }
  intersectsSprite(e) {
    return Pn.center.set(0, 0, 0), Pn.radius = 0.7071067811865476, Pn.applyMatrix4(e.matrixWorld), this.intersectsSphere(Pn);
  }
  intersectsSphere(e) {
    const t = this.planes, r = e.center, n = -e.radius;
    for (let i = 0; i < 6; i++)
      if (t[i].distanceToPoint(r) < n)
        return !1;
    return !0;
  }
  intersectsBox(e) {
    const t = this.planes;
    for (let r = 0; r < 6; r++) {
      const n = t[r];
      if (vr.x = n.normal.x > 0 ? e.max.x : e.min.x, vr.y = n.normal.y > 0 ? e.max.y : e.min.y, vr.z = n.normal.z > 0 ? e.max.z : e.min.z, n.distanceToPoint(vr) < 0)
        return !1;
    }
    return !0;
  }
  containsPoint(e) {
    const t = this.planes;
    for (let r = 0; r < 6; r++)
      if (t[r].distanceToPoint(e) < 0)
        return !1;
    return !0;
  }
  clone() {
    return new this.constructor().copy(this);
  }
}
function qo() {
  let a = null, e = !1, t = null, r = null;
  function n(i, s) {
    t(i, s), r = a.requestAnimationFrame(n);
  }
  return {
    start: function() {
      e !== !0 && t !== null && (r = a.requestAnimationFrame(n), e = !0);
    },
    stop: function() {
      a.cancelAnimationFrame(r), e = !1;
    },
    setAnimationLoop: function(i) {
      t = i;
    },
    setContext: function(i) {
      a = i;
    }
  };
}
function Jl(a) {
  const e = /* @__PURE__ */ new WeakMap();
  function t(o, l) {
    const c = o.array, u = o.usage, f = c.byteLength, h = a.createBuffer();
    a.bindBuffer(l, h), a.bufferData(l, c, u), o.onUploadCallback();
    let d;
    if (c instanceof Float32Array)
      d = a.FLOAT;
    else if (c instanceof Uint16Array)
      o.isFloat16BufferAttribute ? d = a.HALF_FLOAT : d = a.UNSIGNED_SHORT;
    else if (c instanceof Int16Array)
      d = a.SHORT;
    else if (c instanceof Uint32Array)
      d = a.UNSIGNED_INT;
    else if (c instanceof Int32Array)
      d = a.INT;
    else if (c instanceof Int8Array)
      d = a.BYTE;
    else if (c instanceof Uint8Array)
      d = a.UNSIGNED_BYTE;
    else if (c instanceof Uint8ClampedArray)
      d = a.UNSIGNED_BYTE;
    else
      throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: " + c);
    return {
      buffer: h,
      type: d,
      bytesPerElement: c.BYTES_PER_ELEMENT,
      version: o.version,
      size: f
    };
  }
  function r(o, l, c) {
    const u = l.array, f = l.updateRanges;
    if (a.bindBuffer(c, o), f.length === 0)
      a.bufferSubData(c, 0, u);
    else {
      f.sort((d, g) => d.start - g.start);
      let h = 0;
      for (let d = 1; d < f.length; d++) {
        const g = f[h], v = f[d];
        v.start <= g.start + g.count + 1 ? g.count = Math.max(
          g.count,
          v.start + v.count - g.start
        ) : (++h, f[h] = v);
      }
      f.length = h + 1;
      for (let d = 0, g = f.length; d < g; d++) {
        const v = f[d];
        a.bufferSubData(
          c,
          v.start * u.BYTES_PER_ELEMENT,
          u,
          v.start,
          v.count
        );
      }
      l.clearUpdateRanges();
    }
    l.onUploadCallback();
  }
  function n(o) {
    return o.isInterleavedBufferAttribute && (o = o.data), e.get(o);
  }
  function i(o) {
    o.isInterleavedBufferAttribute && (o = o.data);
    const l = e.get(o);
    l && (a.deleteBuffer(l.buffer), e.delete(o));
  }
  function s(o, l) {
    if (o.isInterleavedBufferAttribute && (o = o.data), o.isGLBufferAttribute) {
      const u = e.get(o);
      (!u || u.version < o.version) && e.set(o, {
        buffer: o.buffer,
        type: o.type,
        bytesPerElement: o.elementSize,
        version: o.version
      });
      return;
    }
    const c = e.get(o);
    if (c === void 0)
      e.set(o, t(o, l));
    else if (c.version < o.version) {
      if (c.size !== o.array.byteLength)
        throw new Error("THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.");
      r(c.buffer, o, l), c.version = o.version;
    }
  }
  return {
    get: n,
    remove: i,
    update: s
  };
}
class zn extends St {
  constructor(e = 1, t = 1, r = 1, n = 1) {
    super(), this.type = "PlaneGeometry", this.parameters = {
      width: e,
      height: t,
      widthSegments: r,
      heightSegments: n
    };
    const i = e / 2, s = t / 2, o = Math.floor(r), l = Math.floor(n), c = o + 1, u = l + 1, f = e / o, h = t / l, d = [], g = [], v = [], m = [];
    for (let p = 0; p < u; p++) {
      const T = p * h - s;
      for (let x = 0; x < c; x++) {
        const _ = x * f - i;
        g.push(_, -T, 0), v.push(0, 0, 1), m.push(x / o), m.push(1 - p / l);
      }
    }
    for (let p = 0; p < l; p++)
      for (let T = 0; T < o; T++) {
        const x = T + c * p, _ = T + c * (p + 1), D = T + 1 + c * (p + 1), C = T + 1 + c * p;
        d.push(x, _, C), d.push(_, D, C);
      }
    this.setIndex(d), this.setAttribute("position", new tn(g, 3)), this.setAttribute("normal", new tn(v, 3)), this.setAttribute("uv", new tn(m, 2));
  }
  copy(e) {
    return super.copy(e), this.parameters = Object.assign({}, e.parameters), this;
  }
  static fromJSON(e) {
    return new zn(e.width, e.height, e.widthSegments, e.heightSegments);
  }
}
var Ql = `#ifdef USE_ALPHAHASH
	if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
#endif`, $l = `#ifdef USE_ALPHAHASH
	const float ALPHA_HASH_SCALE = 0.05;
	float hash2D( vec2 value ) {
		return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );
	}
	float hash3D( vec3 value ) {
		return hash2D( vec2( hash2D( value.xy ), value.z ) );
	}
	float getAlphaHashThreshold( vec3 position ) {
		float maxDeriv = max(
			length( dFdx( position.xyz ) ),
			length( dFdy( position.xyz ) )
		);
		float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );
		vec2 pixScales = vec2(
			exp2( floor( log2( pixScale ) ) ),
			exp2( ceil( log2( pixScale ) ) )
		);
		vec2 alpha = vec2(
			hash3D( floor( pixScales.x * position.xyz ) ),
			hash3D( floor( pixScales.y * position.xyz ) )
		);
		float lerpFactor = fract( log2( pixScale ) );
		float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;
		float a = min( lerpFactor, 1.0 - lerpFactor );
		vec3 cases = vec3(
			x * x / ( 2.0 * a * ( 1.0 - a ) ),
			( x - 0.5 * a ) / ( 1.0 - a ),
			1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )
		);
		float threshold = ( x < ( 1.0 - a ) )
			? ( ( x < a ) ? cases.x : cases.y )
			: cases.z;
		return clamp( threshold , 1.0e-6, 1.0 );
	}
#endif`, ec = `#ifdef USE_ALPHAMAP
	diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;
#endif`, tc = `#ifdef USE_ALPHAMAP
	uniform sampler2D alphaMap;
#endif`, nc = `#ifdef USE_ALPHATEST
	#ifdef ALPHA_TO_COVERAGE
	diffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );
	if ( diffuseColor.a == 0.0 ) discard;
	#else
	if ( diffuseColor.a < alphaTest ) discard;
	#endif
#endif`, ic = `#ifdef USE_ALPHATEST
	uniform float alphaTest;
#endif`, rc = `#ifdef USE_AOMAP
	float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;
	reflectedLight.indirectDiffuse *= ambientOcclusion;
	#if defined( USE_CLEARCOAT ) 
		clearcoatSpecularIndirect *= ambientOcclusion;
	#endif
	#if defined( USE_SHEEN ) 
		sheenSpecularIndirect *= ambientOcclusion;
	#endif
	#if defined( USE_ENVMAP ) && defined( STANDARD )
		float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
		reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
	#endif
#endif`, ac = `#ifdef USE_AOMAP
	uniform sampler2D aoMap;
	uniform float aoMapIntensity;
#endif`, sc = `#ifdef USE_BATCHING
	#if ! defined( GL_ANGLE_multi_draw )
	#define gl_DrawID _gl_DrawID
	uniform int _gl_DrawID;
	#endif
	uniform highp sampler2D batchingTexture;
	uniform highp usampler2D batchingIdTexture;
	mat4 getBatchingMatrix( const in float i ) {
		int size = textureSize( batchingTexture, 0 ).x;
		int j = int( i ) * 4;
		int x = j % size;
		int y = j / size;
		vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
		vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
		vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
		vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
		return mat4( v1, v2, v3, v4 );
	}
	float getIndirectIndex( const in int i ) {
		int size = textureSize( batchingIdTexture, 0 ).x;
		int x = i % size;
		int y = i / size;
		return float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );
	}
#endif
#ifdef USE_BATCHING_COLOR
	uniform sampler2D batchingColorTexture;
	vec3 getBatchingColor( const in float i ) {
		int size = textureSize( batchingColorTexture, 0 ).x;
		int j = int( i );
		int x = j % size;
		int y = j / size;
		return texelFetch( batchingColorTexture, ivec2( x, y ), 0 ).rgb;
	}
#endif`, oc = `#ifdef USE_BATCHING
	mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );
#endif`, lc = `vec3 transformed = vec3( position );
#ifdef USE_ALPHAHASH
	vPosition = vec3( position );
#endif`, cc = `vec3 objectNormal = vec3( normal );
#ifdef USE_TANGENT
	vec3 objectTangent = vec3( tangent.xyz );
#endif`, uc = `float G_BlinnPhong_Implicit( ) {
	return 0.25;
}
float D_BlinnPhong( const in float shininess, const in float dotNH ) {
	return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
}
vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {
	vec3 halfDir = normalize( lightDir + viewDir );
	float dotNH = saturate( dot( normal, halfDir ) );
	float dotVH = saturate( dot( viewDir, halfDir ) );
	vec3 F = F_Schlick( specularColor, 1.0, dotVH );
	float G = G_BlinnPhong_Implicit( );
	float D = D_BlinnPhong( shininess, dotNH );
	return F * ( G * D );
} // validated`, hc = `#ifdef USE_IRIDESCENCE
	const mat3 XYZ_TO_REC709 = mat3(
		 3.2404542, -0.9692660,  0.0556434,
		-1.5371385,  1.8760108, -0.2040259,
		-0.4985314,  0.0415560,  1.0572252
	);
	vec3 Fresnel0ToIor( vec3 fresnel0 ) {
		vec3 sqrtF0 = sqrt( fresnel0 );
		return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );
	}
	vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {
		return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );
	}
	float IorToFresnel0( float transmittedIor, float incidentIor ) {
		return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));
	}
	vec3 evalSensitivity( float OPD, vec3 shift ) {
		float phase = 2.0 * PI * OPD * 1.0e-9;
		vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
		vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
		vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
		vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );
		xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );
		xyz /= 1.0685e-7;
		vec3 rgb = XYZ_TO_REC709 * xyz;
		return rgb;
	}
	vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {
		vec3 I;
		float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
		float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );
		float cosTheta2Sq = 1.0 - sinTheta2Sq;
		if ( cosTheta2Sq < 0.0 ) {
			return vec3( 1.0 );
		}
		float cosTheta2 = sqrt( cosTheta2Sq );
		float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );
		float R12 = F_Schlick( R0, 1.0, cosTheta1 );
		float T121 = 1.0 - R12;
		float phi12 = 0.0;
		if ( iridescenceIOR < outsideIOR ) phi12 = PI;
		float phi21 = PI - phi12;
		vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) );		vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );
		vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );
		vec3 phi23 = vec3( 0.0 );
		if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;
		if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;
		if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;
		float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;
		vec3 phi = vec3( phi21 ) + phi23;
		vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );
		vec3 r123 = sqrt( R123 );
		vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );
		vec3 C0 = R12 + Rs;
		I = C0;
		vec3 Cm = Rs - T121;
		for ( int m = 1; m <= 2; ++ m ) {
			Cm *= r123;
			vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );
			I += Cm * Sm;
		}
		return max( I, vec3( 0.0 ) );
	}
#endif`, fc = `#ifdef USE_BUMPMAP
	uniform sampler2D bumpMap;
	uniform float bumpScale;
	vec2 dHdxy_fwd() {
		vec2 dSTdx = dFdx( vBumpMapUv );
		vec2 dSTdy = dFdy( vBumpMapUv );
		float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;
		float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;
		float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;
		return vec2( dBx, dBy );
	}
	vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {
		vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );
		vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );
		vec3 vN = surf_norm;
		vec3 R1 = cross( vSigmaY, vN );
		vec3 R2 = cross( vN, vSigmaX );
		float fDet = dot( vSigmaX, R1 ) * faceDirection;
		vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
		return normalize( abs( fDet ) * surf_norm - vGrad );
	}
#endif`, dc = `#if NUM_CLIPPING_PLANES > 0
	vec4 plane;
	#ifdef ALPHA_TO_COVERAGE
		float distanceToPlane, distanceGradient;
		float clipOpacity = 1.0;
		#pragma unroll_loop_start
		for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
			plane = clippingPlanes[ i ];
			distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
			distanceGradient = fwidth( distanceToPlane ) / 2.0;
			clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
			if ( clipOpacity == 0.0 ) discard;
		}
		#pragma unroll_loop_end
		#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
			float unionClipOpacity = 1.0;
			#pragma unroll_loop_start
			for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
				plane = clippingPlanes[ i ];
				distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
				distanceGradient = fwidth( distanceToPlane ) / 2.0;
				unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
			}
			#pragma unroll_loop_end
			clipOpacity *= 1.0 - unionClipOpacity;
		#endif
		diffuseColor.a *= clipOpacity;
		if ( diffuseColor.a == 0.0 ) discard;
	#else
		#pragma unroll_loop_start
		for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
			plane = clippingPlanes[ i ];
			if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;
		}
		#pragma unroll_loop_end
		#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
			bool clipped = true;
			#pragma unroll_loop_start
			for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
				plane = clippingPlanes[ i ];
				clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;
			}
			#pragma unroll_loop_end
			if ( clipped ) discard;
		#endif
	#endif
#endif`, pc = `#if NUM_CLIPPING_PLANES > 0
	varying vec3 vClipPosition;
	uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
#endif`, mc = `#if NUM_CLIPPING_PLANES > 0
	varying vec3 vClipPosition;
#endif`, gc = `#if NUM_CLIPPING_PLANES > 0
	vClipPosition = - mvPosition.xyz;
#endif`, vc = `#if defined( USE_COLOR_ALPHA )
	diffuseColor *= vColor;
#elif defined( USE_COLOR )
	diffuseColor.rgb *= vColor;
#endif`, _c = `#if defined( USE_COLOR_ALPHA )
	varying vec4 vColor;
#elif defined( USE_COLOR )
	varying vec3 vColor;
#endif`, xc = `#if defined( USE_COLOR_ALPHA )
	varying vec4 vColor;
#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
	varying vec3 vColor;
#endif`, Sc = `#if defined( USE_COLOR_ALPHA )
	vColor = vec4( 1.0 );
#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
	vColor = vec3( 1.0 );
#endif
#ifdef USE_COLOR
	vColor *= color;
#endif
#ifdef USE_INSTANCING_COLOR
	vColor.xyz *= instanceColor.xyz;
#endif
#ifdef USE_BATCHING_COLOR
	vec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );
	vColor.xyz *= batchingColor.xyz;
#endif`, yc = `#define PI 3.141592653589793
#define PI2 6.283185307179586
#define PI_HALF 1.5707963267948966
#define RECIPROCAL_PI 0.3183098861837907
#define RECIPROCAL_PI2 0.15915494309189535
#define EPSILON 1e-6
#ifndef saturate
#define saturate( a ) clamp( a, 0.0, 1.0 )
#endif
#define whiteComplement( a ) ( 1.0 - saturate( a ) )
float pow2( const in float x ) { return x*x; }
vec3 pow2( const in vec3 x ) { return x*x; }
float pow3( const in float x ) { return x*x*x; }
float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }
highp float rand( const in vec2 uv ) {
	const highp float a = 12.9898, b = 78.233, c = 43758.5453;
	highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
	return fract( sin( sn ) * c );
}
#ifdef HIGH_PRECISION
	float precisionSafeLength( vec3 v ) { return length( v ); }
#else
	float precisionSafeLength( vec3 v ) {
		float maxComponent = max3( abs( v ) );
		return length( v / maxComponent ) * maxComponent;
	}
#endif
struct IncidentLight {
	vec3 color;
	vec3 direction;
	bool visible;
};
struct ReflectedLight {
	vec3 directDiffuse;
	vec3 directSpecular;
	vec3 indirectDiffuse;
	vec3 indirectSpecular;
};
#ifdef USE_ALPHAHASH
	varying vec3 vPosition;
#endif
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
	return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
}
vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
	return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
}
mat3 transposeMat3( const in mat3 m ) {
	mat3 tmp;
	tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );
	tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );
	tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );
	return tmp;
}
bool isPerspectiveMatrix( mat4 m ) {
	return m[ 2 ][ 3 ] == - 1.0;
}
vec2 equirectUv( in vec3 dir ) {
	float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;
	float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
	return vec2( u, v );
}
vec3 BRDF_Lambert( const in vec3 diffuseColor ) {
	return RECIPROCAL_PI * diffuseColor;
}
vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
	float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
	return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
}
float F_Schlick( const in float f0, const in float f90, const in float dotVH ) {
	float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
	return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
} // validated`, Mc = `#ifdef ENVMAP_TYPE_CUBE_UV
	#define cubeUV_minMipLevel 4.0
	#define cubeUV_minTileSize 16.0
	float getFace( vec3 direction ) {
		vec3 absDirection = abs( direction );
		float face = - 1.0;
		if ( absDirection.x > absDirection.z ) {
			if ( absDirection.x > absDirection.y )
				face = direction.x > 0.0 ? 0.0 : 3.0;
			else
				face = direction.y > 0.0 ? 1.0 : 4.0;
		} else {
			if ( absDirection.z > absDirection.y )
				face = direction.z > 0.0 ? 2.0 : 5.0;
			else
				face = direction.y > 0.0 ? 1.0 : 4.0;
		}
		return face;
	}
	vec2 getUV( vec3 direction, float face ) {
		vec2 uv;
		if ( face == 0.0 ) {
			uv = vec2( direction.z, direction.y ) / abs( direction.x );
		} else if ( face == 1.0 ) {
			uv = vec2( - direction.x, - direction.z ) / abs( direction.y );
		} else if ( face == 2.0 ) {
			uv = vec2( - direction.x, direction.y ) / abs( direction.z );
		} else if ( face == 3.0 ) {
			uv = vec2( - direction.z, direction.y ) / abs( direction.x );
		} else if ( face == 4.0 ) {
			uv = vec2( - direction.x, direction.z ) / abs( direction.y );
		} else {
			uv = vec2( direction.x, direction.y ) / abs( direction.z );
		}
		return 0.5 * ( uv + 1.0 );
	}
	vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {
		float face = getFace( direction );
		float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );
		mipInt = max( mipInt, cubeUV_minMipLevel );
		float faceSize = exp2( mipInt );
		highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;
		if ( face > 2.0 ) {
			uv.y += faceSize;
			face -= 3.0;
		}
		uv.x += face * faceSize;
		uv.x += filterInt * 3.0 * cubeUV_minTileSize;
		uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );
		uv.x *= CUBEUV_TEXEL_WIDTH;
		uv.y *= CUBEUV_TEXEL_HEIGHT;
		#ifdef texture2DGradEXT
			return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;
		#else
			return texture2D( envMap, uv ).rgb;
		#endif
	}
	#define cubeUV_r0 1.0
	#define cubeUV_m0 - 2.0
	#define cubeUV_r1 0.8
	#define cubeUV_m1 - 1.0
	#define cubeUV_r4 0.4
	#define cubeUV_m4 2.0
	#define cubeUV_r5 0.305
	#define cubeUV_m5 3.0
	#define cubeUV_r6 0.21
	#define cubeUV_m6 4.0
	float roughnessToMip( float roughness ) {
		float mip = 0.0;
		if ( roughness >= cubeUV_r1 ) {
			mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;
		} else if ( roughness >= cubeUV_r4 ) {
			mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;
		} else if ( roughness >= cubeUV_r5 ) {
			mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;
		} else if ( roughness >= cubeUV_r6 ) {
			mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;
		} else {
			mip = - 2.0 * log2( 1.16 * roughness );		}
		return mip;
	}
	vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {
		float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );
		float mipF = fract( mip );
		float mipInt = floor( mip );
		vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );
		if ( mipF == 0.0 ) {
			return vec4( color0, 1.0 );
		} else {
			vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );
			return vec4( mix( color0, color1, mipF ), 1.0 );
		}
	}
#endif`, Ec = `vec3 transformedNormal = objectNormal;
#ifdef USE_TANGENT
	vec3 transformedTangent = objectTangent;
#endif
#ifdef USE_BATCHING
	mat3 bm = mat3( batchingMatrix );
	transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );
	transformedNormal = bm * transformedNormal;
	#ifdef USE_TANGENT
		transformedTangent = bm * transformedTangent;
	#endif
#endif
#ifdef USE_INSTANCING
	mat3 im = mat3( instanceMatrix );
	transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );
	transformedNormal = im * transformedNormal;
	#ifdef USE_TANGENT
		transformedTangent = im * transformedTangent;
	#endif
#endif
transformedNormal = normalMatrix * transformedNormal;
#ifdef FLIP_SIDED
	transformedNormal = - transformedNormal;
#endif
#ifdef USE_TANGENT
	transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;
	#ifdef FLIP_SIDED
		transformedTangent = - transformedTangent;
	#endif
#endif`, Tc = `#ifdef USE_DISPLACEMENTMAP
	uniform sampler2D displacementMap;
	uniform float displacementScale;
	uniform float displacementBias;
#endif`, bc = `#ifdef USE_DISPLACEMENTMAP
	transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );
#endif`, Ac = `#ifdef USE_EMISSIVEMAP
	vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
	#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE
		emissiveColor = sRGBTransferEOTF( emissiveColor );
	#endif
	totalEmissiveRadiance *= emissiveColor.rgb;
#endif`, wc = `#ifdef USE_EMISSIVEMAP
	uniform sampler2D emissiveMap;
#endif`, Cc = "gl_FragColor = linearToOutputTexel( gl_FragColor );", Rc = `vec4 LinearTransferOETF( in vec4 value ) {
	return value;
}
vec4 sRGBTransferEOTF( in vec4 value ) {
	return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );
}
vec4 sRGBTransferOETF( in vec4 value ) {
	return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );
}`, Pc = `#ifdef USE_ENVMAP
	#ifdef ENV_WORLDPOS
		vec3 cameraToFrag;
		if ( isOrthographic ) {
			cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
		} else {
			cameraToFrag = normalize( vWorldPosition - cameraPosition );
		}
		vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
		#ifdef ENVMAP_MODE_REFLECTION
			vec3 reflectVec = reflect( cameraToFrag, worldNormal );
		#else
			vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );
		#endif
	#else
		vec3 reflectVec = vReflect;
	#endif
	#ifdef ENVMAP_TYPE_CUBE
		vec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
	#else
		vec4 envColor = vec4( 0.0 );
	#endif
	#ifdef ENVMAP_BLENDING_MULTIPLY
		outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
	#elif defined( ENVMAP_BLENDING_MIX )
		outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
	#elif defined( ENVMAP_BLENDING_ADD )
		outgoingLight += envColor.xyz * specularStrength * reflectivity;
	#endif
#endif`, Uc = `#ifdef USE_ENVMAP
	uniform float envMapIntensity;
	uniform float flipEnvMap;
	uniform mat3 envMapRotation;
	#ifdef ENVMAP_TYPE_CUBE
		uniform samplerCube envMap;
	#else
		uniform sampler2D envMap;
	#endif
	
#endif`, Dc = `#ifdef USE_ENVMAP
	uniform float reflectivity;
	#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
		#define ENV_WORLDPOS
	#endif
	#ifdef ENV_WORLDPOS
		varying vec3 vWorldPosition;
		uniform float refractionRatio;
	#else
		varying vec3 vReflect;
	#endif
#endif`, Lc = `#ifdef USE_ENVMAP
	#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
		#define ENV_WORLDPOS
	#endif
	#ifdef ENV_WORLDPOS
		
		varying vec3 vWorldPosition;
	#else
		varying vec3 vReflect;
		uniform float refractionRatio;
	#endif
#endif`, Fc = `#ifdef USE_ENVMAP
	#ifdef ENV_WORLDPOS
		vWorldPosition = worldPosition.xyz;
	#else
		vec3 cameraToVertex;
		if ( isOrthographic ) {
			cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
		} else {
			cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
		}
		vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
		#ifdef ENVMAP_MODE_REFLECTION
			vReflect = reflect( cameraToVertex, worldNormal );
		#else
			vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
		#endif
	#endif
#endif`, Ic = `#ifdef USE_FOG
	vFogDepth = - mvPosition.z;
#endif`, Nc = `#ifdef USE_FOG
	varying float vFogDepth;
#endif`, Oc = `#ifdef USE_FOG
	#ifdef FOG_EXP2
		float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );
	#else
		float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );
	#endif
	gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
#endif`, Bc = `#ifdef USE_FOG
	uniform vec3 fogColor;
	varying float vFogDepth;
	#ifdef FOG_EXP2
		uniform float fogDensity;
	#else
		uniform float fogNear;
		uniform float fogFar;
	#endif
#endif`, kc = `#ifdef USE_GRADIENTMAP
	uniform sampler2D gradientMap;
#endif
vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
	float dotNL = dot( normal, lightDirection );
	vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );
	#ifdef USE_GRADIENTMAP
		return vec3( texture2D( gradientMap, coord ).r );
	#else
		vec2 fw = fwidth( coord ) * 0.5;
		return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );
	#endif
}`, Gc = `#ifdef USE_LIGHTMAP
	uniform sampler2D lightMap;
	uniform float lightMapIntensity;
#endif`, zc = `LambertMaterial material;
material.diffuseColor = diffuseColor.rgb;
material.specularStrength = specularStrength;`, Vc = `varying vec3 vViewPosition;
struct LambertMaterial {
	vec3 diffuseColor;
	float specularStrength;
};
void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
	float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
	vec3 irradiance = dotNL * directLight.color;
	reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
	reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
#define RE_Direct				RE_Direct_Lambert
#define RE_IndirectDiffuse		RE_IndirectDiffuse_Lambert`, Hc = `uniform bool receiveShadow;
uniform vec3 ambientLightColor;
#if defined( USE_LIGHT_PROBES )
	uniform vec3 lightProbe[ 9 ];
#endif
vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
	float x = normal.x, y = normal.y, z = normal.z;
	vec3 result = shCoefficients[ 0 ] * 0.886227;
	result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
	result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
	result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
	result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
	result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
	result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
	result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
	result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
	return result;
}
vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {
	vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
	vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
	return irradiance;
}
vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
	vec3 irradiance = ambientLightColor;
	return irradiance;
}
float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
	float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
	if ( cutoffDistance > 0.0 ) {
		distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
	}
	return distanceFalloff;
}
float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
	return smoothstep( coneCosine, penumbraCosine, angleCosine );
}
#if NUM_DIR_LIGHTS > 0
	struct DirectionalLight {
		vec3 direction;
		vec3 color;
	};
	uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
	void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {
		light.color = directionalLight.color;
		light.direction = directionalLight.direction;
		light.visible = true;
	}
#endif
#if NUM_POINT_LIGHTS > 0
	struct PointLight {
		vec3 position;
		vec3 color;
		float distance;
		float decay;
	};
	uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
	void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {
		vec3 lVector = pointLight.position - geometryPosition;
		light.direction = normalize( lVector );
		float lightDistance = length( lVector );
		light.color = pointLight.color;
		light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
		light.visible = ( light.color != vec3( 0.0 ) );
	}
#endif
#if NUM_SPOT_LIGHTS > 0
	struct SpotLight {
		vec3 position;
		vec3 direction;
		vec3 color;
		float distance;
		float decay;
		float coneCos;
		float penumbraCos;
	};
	uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
	void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {
		vec3 lVector = spotLight.position - geometryPosition;
		light.direction = normalize( lVector );
		float angleCos = dot( light.direction, spotLight.direction );
		float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
		if ( spotAttenuation > 0.0 ) {
			float lightDistance = length( lVector );
			light.color = spotLight.color * spotAttenuation;
			light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );
			light.visible = ( light.color != vec3( 0.0 ) );
		} else {
			light.color = vec3( 0.0 );
			light.visible = false;
		}
	}
#endif
#if NUM_RECT_AREA_LIGHTS > 0
	struct RectAreaLight {
		vec3 color;
		vec3 position;
		vec3 halfWidth;
		vec3 halfHeight;
	};
	uniform sampler2D ltc_1;	uniform sampler2D ltc_2;
	uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];
#endif
#if NUM_HEMI_LIGHTS > 0
	struct HemisphereLight {
		vec3 direction;
		vec3 skyColor;
		vec3 groundColor;
	};
	uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];
	vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {
		float dotNL = dot( normal, hemiLight.direction );
		float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
		vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
		return irradiance;
	}
#endif`, Wc = `#ifdef USE_ENVMAP
	vec3 getIBLIrradiance( const in vec3 normal ) {
		#ifdef ENVMAP_TYPE_CUBE_UV
			vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
			vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );
			return PI * envMapColor.rgb * envMapIntensity;
		#else
			return vec3( 0.0 );
		#endif
	}
	vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
		#ifdef ENVMAP_TYPE_CUBE_UV
			vec3 reflectVec = reflect( - viewDir, normal );
			reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
			reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
			vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );
			return envMapColor.rgb * envMapIntensity;
		#else
			return vec3( 0.0 );
		#endif
	}
	#ifdef USE_ANISOTROPY
		vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {
			#ifdef ENVMAP_TYPE_CUBE_UV
				vec3 bentNormal = cross( bitangent, viewDir );
				bentNormal = normalize( cross( bentNormal, bitangent ) );
				bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );
				return getIBLRadiance( viewDir, bentNormal, roughness );
			#else
				return vec3( 0.0 );
			#endif
		}
	#endif
#endif`, Xc = `ToonMaterial material;
material.diffuseColor = diffuseColor.rgb;`, qc = `varying vec3 vViewPosition;
struct ToonMaterial {
	vec3 diffuseColor;
};
void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
	vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;
	reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
	reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
#define RE_Direct				RE_Direct_Toon
#define RE_IndirectDiffuse		RE_IndirectDiffuse_Toon`, Yc = `BlinnPhongMaterial material;
material.diffuseColor = diffuseColor.rgb;
material.specularColor = specular;
material.specularShininess = shininess;
material.specularStrength = specularStrength;`, jc = `varying vec3 vViewPosition;
struct BlinnPhongMaterial {
	vec3 diffuseColor;
	vec3 specularColor;
	float specularShininess;
	float specularStrength;
};
void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
	float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
	vec3 irradiance = dotNL * directLight.color;
	reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
	reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;
}
void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
	reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
#define RE_Direct				RE_Direct_BlinnPhong
#define RE_IndirectDiffuse		RE_IndirectDiffuse_BlinnPhong`, Zc = `PhysicalMaterial material;
material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );
float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;
material.roughness = min( material.roughness, 1.0 );
#ifdef IOR
	material.ior = ior;
	#ifdef USE_SPECULAR
		float specularIntensityFactor = specularIntensity;
		vec3 specularColorFactor = specularColor;
		#ifdef USE_SPECULAR_COLORMAP
			specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;
		#endif
		#ifdef USE_SPECULAR_INTENSITYMAP
			specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;
		#endif
		material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );
	#else
		float specularIntensityFactor = 1.0;
		vec3 specularColorFactor = vec3( 1.0 );
		material.specularF90 = 1.0;
	#endif
	material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );
#else
	material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
	material.specularF90 = 1.0;
#endif
#ifdef USE_CLEARCOAT
	material.clearcoat = clearcoat;
	material.clearcoatRoughness = clearcoatRoughness;
	material.clearcoatF0 = vec3( 0.04 );
	material.clearcoatF90 = 1.0;
	#ifdef USE_CLEARCOATMAP
		material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;
	#endif
	#ifdef USE_CLEARCOAT_ROUGHNESSMAP
		material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;
	#endif
	material.clearcoat = saturate( material.clearcoat );	material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );
	material.clearcoatRoughness += geometryRoughness;
	material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
#endif
#ifdef USE_DISPERSION
	material.dispersion = dispersion;
#endif
#ifdef USE_IRIDESCENCE
	material.iridescence = iridescence;
	material.iridescenceIOR = iridescenceIOR;
	#ifdef USE_IRIDESCENCEMAP
		material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;
	#endif
	#ifdef USE_IRIDESCENCE_THICKNESSMAP
		material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;
	#else
		material.iridescenceThickness = iridescenceThicknessMaximum;
	#endif
#endif
#ifdef USE_SHEEN
	material.sheenColor = sheenColor;
	#ifdef USE_SHEEN_COLORMAP
		material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;
	#endif
	material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );
	#ifdef USE_SHEEN_ROUGHNESSMAP
		material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;
	#endif
#endif
#ifdef USE_ANISOTROPY
	#ifdef USE_ANISOTROPYMAP
		mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );
		vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;
		vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;
	#else
		vec2 anisotropyV = anisotropyVector;
	#endif
	material.anisotropy = length( anisotropyV );
	if( material.anisotropy == 0.0 ) {
		anisotropyV = vec2( 1.0, 0.0 );
	} else {
		anisotropyV /= material.anisotropy;
		material.anisotropy = saturate( material.anisotropy );
	}
	material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );
	material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;
	material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;
#endif`, Kc = `struct PhysicalMaterial {
	vec3 diffuseColor;
	float roughness;
	vec3 specularColor;
	float specularF90;
	float dispersion;
	#ifdef USE_CLEARCOAT
		float clearcoat;
		float clearcoatRoughness;
		vec3 clearcoatF0;
		float clearcoatF90;
	#endif
	#ifdef USE_IRIDESCENCE
		float iridescence;
		float iridescenceIOR;
		float iridescenceThickness;
		vec3 iridescenceFresnel;
		vec3 iridescenceF0;
	#endif
	#ifdef USE_SHEEN
		vec3 sheenColor;
		float sheenRoughness;
	#endif
	#ifdef IOR
		float ior;
	#endif
	#ifdef USE_TRANSMISSION
		float transmission;
		float transmissionAlpha;
		float thickness;
		float attenuationDistance;
		vec3 attenuationColor;
	#endif
	#ifdef USE_ANISOTROPY
		float anisotropy;
		float alphaT;
		vec3 anisotropyT;
		vec3 anisotropyB;
	#endif
};
vec3 clearcoatSpecularDirect = vec3( 0.0 );
vec3 clearcoatSpecularIndirect = vec3( 0.0 );
vec3 sheenSpecularDirect = vec3( 0.0 );
vec3 sheenSpecularIndirect = vec3(0.0 );
vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {
    float x = clamp( 1.0 - dotVH, 0.0, 1.0 );
    float x2 = x * x;
    float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );
    return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );
}
float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
	float a2 = pow2( alpha );
	float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
	float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
	return 0.5 / max( gv + gl, EPSILON );
}
float D_GGX( const in float alpha, const in float dotNH ) {
	float a2 = pow2( alpha );
	float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
	return RECIPROCAL_PI * a2 / pow2( denom );
}
#ifdef USE_ANISOTROPY
	float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {
		float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );
		float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );
		float v = 0.5 / ( gv + gl );
		return saturate(v);
	}
	float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {
		float a2 = alphaT * alphaB;
		highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );
		highp float v2 = dot( v, v );
		float w2 = a2 / v2;
		return RECIPROCAL_PI * a2 * pow2 ( w2 );
	}
#endif
#ifdef USE_CLEARCOAT
	vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {
		vec3 f0 = material.clearcoatF0;
		float f90 = material.clearcoatF90;
		float roughness = material.clearcoatRoughness;
		float alpha = pow2( roughness );
		vec3 halfDir = normalize( lightDir + viewDir );
		float dotNL = saturate( dot( normal, lightDir ) );
		float dotNV = saturate( dot( normal, viewDir ) );
		float dotNH = saturate( dot( normal, halfDir ) );
		float dotVH = saturate( dot( viewDir, halfDir ) );
		vec3 F = F_Schlick( f0, f90, dotVH );
		float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
		float D = D_GGX( alpha, dotNH );
		return F * ( V * D );
	}
#endif
vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {
	vec3 f0 = material.specularColor;
	float f90 = material.specularF90;
	float roughness = material.roughness;
	float alpha = pow2( roughness );
	vec3 halfDir = normalize( lightDir + viewDir );
	float dotNL = saturate( dot( normal, lightDir ) );
	float dotNV = saturate( dot( normal, viewDir ) );
	float dotNH = saturate( dot( normal, halfDir ) );
	float dotVH = saturate( dot( viewDir, halfDir ) );
	vec3 F = F_Schlick( f0, f90, dotVH );
	#ifdef USE_IRIDESCENCE
		F = mix( F, material.iridescenceFresnel, material.iridescence );
	#endif
	#ifdef USE_ANISOTROPY
		float dotTL = dot( material.anisotropyT, lightDir );
		float dotTV = dot( material.anisotropyT, viewDir );
		float dotTH = dot( material.anisotropyT, halfDir );
		float dotBL = dot( material.anisotropyB, lightDir );
		float dotBV = dot( material.anisotropyB, viewDir );
		float dotBH = dot( material.anisotropyB, halfDir );
		float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );
		float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );
	#else
		float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
		float D = D_GGX( alpha, dotNH );
	#endif
	return F * ( V * D );
}
vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
	const float LUT_SIZE = 64.0;
	const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
	const float LUT_BIAS = 0.5 / LUT_SIZE;
	float dotNV = saturate( dot( N, V ) );
	vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
	uv = uv * LUT_SCALE + LUT_BIAS;
	return uv;
}
float LTC_ClippedSphereFormFactor( const in vec3 f ) {
	float l = length( f );
	return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
}
vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
	float x = dot( v1, v2 );
	float y = abs( x );
	float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
	float b = 3.4175940 + ( 4.1616724 + y ) * y;
	float v = a / b;
	float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
	return cross( v1, v2 ) * theta_sintheta;
}
vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
	vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
	vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
	vec3 lightNormal = cross( v1, v2 );
	if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
	vec3 T1, T2;
	T1 = normalize( V - N * dot( V, N ) );
	T2 = - cross( N, T1 );
	mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );
	vec3 coords[ 4 ];
	coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );
	coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );
	coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );
	coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );
	coords[ 0 ] = normalize( coords[ 0 ] );
	coords[ 1 ] = normalize( coords[ 1 ] );
	coords[ 2 ] = normalize( coords[ 2 ] );
	coords[ 3 ] = normalize( coords[ 3 ] );
	vec3 vectorFormFactor = vec3( 0.0 );
	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );
	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );
	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );
	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );
	float result = LTC_ClippedSphereFormFactor( vectorFormFactor );
	return vec3( result );
}
#if defined( USE_SHEEN )
float D_Charlie( float roughness, float dotNH ) {
	float alpha = pow2( roughness );
	float invAlpha = 1.0 / alpha;
	float cos2h = dotNH * dotNH;
	float sin2h = max( 1.0 - cos2h, 0.0078125 );
	return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
}
float V_Neubelt( float dotNV, float dotNL ) {
	return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );
}
vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {
	vec3 halfDir = normalize( lightDir + viewDir );
	float dotNL = saturate( dot( normal, lightDir ) );
	float dotNV = saturate( dot( normal, viewDir ) );
	float dotNH = saturate( dot( normal, halfDir ) );
	float D = D_Charlie( sheenRoughness, dotNH );
	float V = V_Neubelt( dotNV, dotNL );
	return sheenColor * ( D * V );
}
#endif
float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
	float dotNV = saturate( dot( normal, viewDir ) );
	float r2 = roughness * roughness;
	float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;
	float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;
	float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );
	return saturate( DG * RECIPROCAL_PI );
}
vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
	float dotNV = saturate( dot( normal, viewDir ) );
	const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
	const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
	vec4 r = roughness * c0 + c1;
	float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
	vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;
	return fab;
}
vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {
	vec2 fab = DFGApprox( normal, viewDir, roughness );
	return specularColor * fab.x + specularF90 * fab.y;
}
#ifdef USE_IRIDESCENCE
void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
#else
void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
#endif
	vec2 fab = DFGApprox( normal, viewDir, roughness );
	#ifdef USE_IRIDESCENCE
		vec3 Fr = mix( specularColor, iridescenceF0, iridescence );
	#else
		vec3 Fr = specularColor;
	#endif
	vec3 FssEss = Fr * fab.x + specularF90 * fab.y;
	float Ess = fab.x + fab.y;
	float Ems = 1.0 - Ess;
	vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;	vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
	singleScatter += FssEss;
	multiScatter += Fms * Ems;
}
#if NUM_RECT_AREA_LIGHTS > 0
	void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
		vec3 normal = geometryNormal;
		vec3 viewDir = geometryViewDir;
		vec3 position = geometryPosition;
		vec3 lightPos = rectAreaLight.position;
		vec3 halfWidth = rectAreaLight.halfWidth;
		vec3 halfHeight = rectAreaLight.halfHeight;
		vec3 lightColor = rectAreaLight.color;
		float roughness = material.roughness;
		vec3 rectCoords[ 4 ];
		rectCoords[ 0 ] = lightPos + halfWidth - halfHeight;		rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
		rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
		rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
		vec2 uv = LTC_Uv( normal, viewDir, roughness );
		vec4 t1 = texture2D( ltc_1, uv );
		vec4 t2 = texture2D( ltc_2, uv );
		mat3 mInv = mat3(
			vec3( t1.x, 0, t1.y ),
			vec3(    0, 1,    0 ),
			vec3( t1.z, 0, t1.w )
		);
		vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );
		reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
		reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
	}
#endif
void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
	float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
	vec3 irradiance = dotNL * directLight.color;
	#ifdef USE_CLEARCOAT
		float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );
		vec3 ccIrradiance = dotNLcc * directLight.color;
		clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );
	#endif
	#ifdef USE_SHEEN
		sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );
	#endif
	reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );
	reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
	reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {
	#ifdef USE_CLEARCOAT
		clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
	#endif
	#ifdef USE_SHEEN
		sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
	#endif
	vec3 singleScattering = vec3( 0.0 );
	vec3 multiScattering = vec3( 0.0 );
	vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
	#ifdef USE_IRIDESCENCE
		computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );
	#else
		computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );
	#endif
	vec3 totalScattering = singleScattering + multiScattering;
	vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
	reflectedLight.indirectSpecular += radiance * singleScattering;
	reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;
	reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;
}
#define RE_Direct				RE_Direct_Physical
#define RE_Direct_RectArea		RE_Direct_RectArea_Physical
#define RE_IndirectDiffuse		RE_IndirectDiffuse_Physical
#define RE_IndirectSpecular		RE_IndirectSpecular_Physical
float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
	return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
}`, Jc = `
vec3 geometryPosition = - vViewPosition;
vec3 geometryNormal = normal;
vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
vec3 geometryClearcoatNormal = vec3( 0.0 );
#ifdef USE_CLEARCOAT
	geometryClearcoatNormal = clearcoatNormal;
#endif
#ifdef USE_IRIDESCENCE
	float dotNVi = saturate( dot( normal, geometryViewDir ) );
	if ( material.iridescenceThickness == 0.0 ) {
		material.iridescence = 0.0;
	} else {
		material.iridescence = saturate( material.iridescence );
	}
	if ( material.iridescence > 0.0 ) {
		material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );
		material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );
	}
#endif
IncidentLight directLight;
#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
	PointLight pointLight;
	#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
	PointLightShadow pointLightShadow;
	#endif
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
		pointLight = pointLights[ i ];
		getPointLightInfo( pointLight, geometryPosition, directLight );
		#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
		pointLightShadow = pointLightShadows[ i ];
		directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
		#endif
		RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
	}
	#pragma unroll_loop_end
#endif
#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
	SpotLight spotLight;
	vec4 spotColor;
	vec3 spotLightCoord;
	bool inSpotLightMap;
	#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
	SpotLightShadow spotLightShadow;
	#endif
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
		spotLight = spotLights[ i ];
		getSpotLightInfo( spotLight, geometryPosition, directLight );
		#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
		#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX
		#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
		#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS
		#else
		#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
		#endif
		#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )
			spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;
			inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );
			spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );
			directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;
		#endif
		#undef SPOT_LIGHT_MAP_INDEX
		#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
		spotLightShadow = spotLightShadows[ i ];
		directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
		#endif
		RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
	}
	#pragma unroll_loop_end
#endif
#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
	DirectionalLight directionalLight;
	#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
	DirectionalLightShadow directionalLightShadow;
	#endif
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
		directionalLight = directionalLights[ i ];
		getDirectionalLightInfo( directionalLight, directLight );
		#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
		directionalLightShadow = directionalLightShadows[ i ];
		directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
		#endif
		RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
	}
	#pragma unroll_loop_end
#endif
#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
	RectAreaLight rectAreaLight;
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
		rectAreaLight = rectAreaLights[ i ];
		RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
	}
	#pragma unroll_loop_end
#endif
#if defined( RE_IndirectDiffuse )
	vec3 iblIrradiance = vec3( 0.0 );
	vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
	#if defined( USE_LIGHT_PROBES )
		irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
	#endif
	#if ( NUM_HEMI_LIGHTS > 0 )
		#pragma unroll_loop_start
		for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
			irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
		}
		#pragma unroll_loop_end
	#endif
#endif
#if defined( RE_IndirectSpecular )
	vec3 radiance = vec3( 0.0 );
	vec3 clearcoatRadiance = vec3( 0.0 );
#endif`, Qc = `#if defined( RE_IndirectDiffuse )
	#ifdef USE_LIGHTMAP
		vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
		vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
		irradiance += lightMapIrradiance;
	#endif
	#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
		iblIrradiance += getIBLIrradiance( geometryNormal );
	#endif
#endif
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
	#ifdef USE_ANISOTROPY
		radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
	#else
		radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );
	#endif
	#ifdef USE_CLEARCOAT
		clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );
	#endif
#endif`, $c = `#if defined( RE_IndirectDiffuse )
	RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
#endif
#if defined( RE_IndirectSpecular )
	RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
#endif`, eu = `#if defined( USE_LOGDEPTHBUF )
	gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
#endif`, tu = `#if defined( USE_LOGDEPTHBUF )
	uniform float logDepthBufFC;
	varying float vFragDepth;
	varying float vIsPerspective;
#endif`, nu = `#ifdef USE_LOGDEPTHBUF
	varying float vFragDepth;
	varying float vIsPerspective;
#endif`, iu = `#ifdef USE_LOGDEPTHBUF
	vFragDepth = 1.0 + gl_Position.w;
	vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
#endif`, ru = `#ifdef USE_MAP
	vec4 sampledDiffuseColor = texture2D( map, vMapUv );
	#ifdef DECODE_VIDEO_TEXTURE
		sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );
	#endif
	diffuseColor *= sampledDiffuseColor;
#endif`, au = `#ifdef USE_MAP
	uniform sampler2D map;
#endif`, su = `#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
	#if defined( USE_POINTS_UV )
		vec2 uv = vUv;
	#else
		vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
	#endif
#endif
#ifdef USE_MAP
	diffuseColor *= texture2D( map, uv );
#endif
#ifdef USE_ALPHAMAP
	diffuseColor.a *= texture2D( alphaMap, uv ).g;
#endif`, ou = `#if defined( USE_POINTS_UV )
	varying vec2 vUv;
#else
	#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
		uniform mat3 uvTransform;
	#endif
#endif
#ifdef USE_MAP
	uniform sampler2D map;
#endif
#ifdef USE_ALPHAMAP
	uniform sampler2D alphaMap;
#endif`, lu = `float metalnessFactor = metalness;
#ifdef USE_METALNESSMAP
	vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );
	metalnessFactor *= texelMetalness.b;
#endif`, cu = `#ifdef USE_METALNESSMAP
	uniform sampler2D metalnessMap;
#endif`, uu = `#ifdef USE_INSTANCING_MORPH
	float morphTargetInfluences[ MORPHTARGETS_COUNT ];
	float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;
	for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
		morphTargetInfluences[i] =  texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;
	}
#endif`, hu = `#if defined( USE_MORPHCOLORS )
	vColor *= morphTargetBaseInfluence;
	for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
		#if defined( USE_COLOR_ALPHA )
			if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];
		#elif defined( USE_COLOR )
			if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
		#endif
	}
#endif`, fu = `#ifdef USE_MORPHNORMALS
	objectNormal *= morphTargetBaseInfluence;
	for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
		if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];
	}
#endif`, du = `#ifdef USE_MORPHTARGETS
	#ifndef USE_INSTANCING_MORPH
		uniform float morphTargetBaseInfluence;
		uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];
	#endif
	uniform sampler2DArray morphTargetsTexture;
	uniform ivec2 morphTargetsTextureSize;
	vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {
		int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;
		int y = texelIndex / morphTargetsTextureSize.x;
		int x = texelIndex - y * morphTargetsTextureSize.x;
		ivec3 morphUV = ivec3( x, y, morphTargetIndex );
		return texelFetch( morphTargetsTexture, morphUV, 0 );
	}
#endif`, pu = `#ifdef USE_MORPHTARGETS
	transformed *= morphTargetBaseInfluence;
	for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
		if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];
	}
#endif`, mu = `float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
#ifdef FLAT_SHADED
	vec3 fdx = dFdx( vViewPosition );
	vec3 fdy = dFdy( vViewPosition );
	vec3 normal = normalize( cross( fdx, fdy ) );
#else
	vec3 normal = normalize( vNormal );
	#ifdef DOUBLE_SIDED
		normal *= faceDirection;
	#endif
#endif
#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )
	#ifdef USE_TANGENT
		mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
	#else
		mat3 tbn = getTangentFrame( - vViewPosition, normal,
		#if defined( USE_NORMALMAP )
			vNormalMapUv
		#elif defined( USE_CLEARCOAT_NORMALMAP )
			vClearcoatNormalMapUv
		#else
			vUv
		#endif
		);
	#endif
	#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
		tbn[0] *= faceDirection;
		tbn[1] *= faceDirection;
	#endif
#endif
#ifdef USE_CLEARCOAT_NORMALMAP
	#ifdef USE_TANGENT
		mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
	#else
		mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );
	#endif
	#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
		tbn2[0] *= faceDirection;
		tbn2[1] *= faceDirection;
	#endif
#endif
vec3 nonPerturbedNormal = normal;`, gu = `#ifdef USE_NORMALMAP_OBJECTSPACE
	normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
	#ifdef FLIP_SIDED
		normal = - normal;
	#endif
	#ifdef DOUBLE_SIDED
		normal = normal * faceDirection;
	#endif
	normal = normalize( normalMatrix * normal );
#elif defined( USE_NORMALMAP_TANGENTSPACE )
	vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
	mapN.xy *= normalScale;
	normal = normalize( tbn * mapN );
#elif defined( USE_BUMPMAP )
	normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
#endif`, vu = `#ifndef FLAT_SHADED
	varying vec3 vNormal;
	#ifdef USE_TANGENT
		varying vec3 vTangent;
		varying vec3 vBitangent;
	#endif
#endif`, _u = `#ifndef FLAT_SHADED
	varying vec3 vNormal;
	#ifdef USE_TANGENT
		varying vec3 vTangent;
		varying vec3 vBitangent;
	#endif
#endif`, xu = `#ifndef FLAT_SHADED
	vNormal = normalize( transformedNormal );
	#ifdef USE_TANGENT
		vTangent = normalize( transformedTangent );
		vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
	#endif
#endif`, Su = `#ifdef USE_NORMALMAP
	uniform sampler2D normalMap;
	uniform vec2 normalScale;
#endif
#ifdef USE_NORMALMAP_OBJECTSPACE
	uniform mat3 normalMatrix;
#endif
#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )
	mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {
		vec3 q0 = dFdx( eye_pos.xyz );
		vec3 q1 = dFdy( eye_pos.xyz );
		vec2 st0 = dFdx( uv.st );
		vec2 st1 = dFdy( uv.st );
		vec3 N = surf_norm;
		vec3 q1perp = cross( q1, N );
		vec3 q0perp = cross( N, q0 );
		vec3 T = q1perp * st0.x + q0perp * st1.x;
		vec3 B = q1perp * st0.y + q0perp * st1.y;
		float det = max( dot( T, T ), dot( B, B ) );
		float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );
		return mat3( T * scale, B * scale, N );
	}
#endif`, yu = `#ifdef USE_CLEARCOAT
	vec3 clearcoatNormal = nonPerturbedNormal;
#endif`, Mu = `#ifdef USE_CLEARCOAT_NORMALMAP
	vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;
	clearcoatMapN.xy *= clearcoatNormalScale;
	clearcoatNormal = normalize( tbn2 * clearcoatMapN );
#endif`, Eu = `#ifdef USE_CLEARCOATMAP
	uniform sampler2D clearcoatMap;
#endif
#ifdef USE_CLEARCOAT_NORMALMAP
	uniform sampler2D clearcoatNormalMap;
	uniform vec2 clearcoatNormalScale;
#endif
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
	uniform sampler2D clearcoatRoughnessMap;
#endif`, Tu = `#ifdef USE_IRIDESCENCEMAP
	uniform sampler2D iridescenceMap;
#endif
#ifdef USE_IRIDESCENCE_THICKNESSMAP
	uniform sampler2D iridescenceThicknessMap;
#endif`, bu = `#ifdef OPAQUE
diffuseColor.a = 1.0;
#endif
#ifdef USE_TRANSMISSION
diffuseColor.a *= material.transmissionAlpha;
#endif
gl_FragColor = vec4( outgoingLight, diffuseColor.a );`, Au = `vec3 packNormalToRGB( const in vec3 normal ) {
	return normalize( normal ) * 0.5 + 0.5;
}
vec3 unpackRGBToNormal( const in vec3 rgb ) {
	return 2.0 * rgb.xyz - 1.0;
}
const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;
const float Inv255 = 1. / 255.;
const vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );
const vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );
const vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );
const vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );
vec4 packDepthToRGBA( const in float v ) {
	if( v <= 0.0 )
		return vec4( 0., 0., 0., 0. );
	if( v >= 1.0 )
		return vec4( 1., 1., 1., 1. );
	float vuf;
	float af = modf( v * PackFactors.a, vuf );
	float bf = modf( vuf * ShiftRight8, vuf );
	float gf = modf( vuf * ShiftRight8, vuf );
	return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );
}
vec3 packDepthToRGB( const in float v ) {
	if( v <= 0.0 )
		return vec3( 0., 0., 0. );
	if( v >= 1.0 )
		return vec3( 1., 1., 1. );
	float vuf;
	float bf = modf( v * PackFactors.b, vuf );
	float gf = modf( vuf * ShiftRight8, vuf );
	return vec3( vuf * Inv255, gf * PackUpscale, bf );
}
vec2 packDepthToRG( const in float v ) {
	if( v <= 0.0 )
		return vec2( 0., 0. );
	if( v >= 1.0 )
		return vec2( 1., 1. );
	float vuf;
	float gf = modf( v * 256., vuf );
	return vec2( vuf * Inv255, gf );
}
float unpackRGBAToDepth( const in vec4 v ) {
	return dot( v, UnpackFactors4 );
}
float unpackRGBToDepth( const in vec3 v ) {
	return dot( v, UnpackFactors3 );
}
float unpackRGToDepth( const in vec2 v ) {
	return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;
}
vec4 pack2HalfToRGBA( const in vec2 v ) {
	vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );
	return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );
}
vec2 unpackRGBATo2Half( const in vec4 v ) {
	return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
}
float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
	return ( viewZ + near ) / ( near - far );
}
float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {
	return depth * ( near - far ) - near;
}
float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
	return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
}
float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {
	return ( near * far ) / ( ( far - near ) * depth - far );
}`, wu = `#ifdef PREMULTIPLIED_ALPHA
	gl_FragColor.rgb *= gl_FragColor.a;
#endif`, Cu = `vec4 mvPosition = vec4( transformed, 1.0 );
#ifdef USE_BATCHING
	mvPosition = batchingMatrix * mvPosition;
#endif
#ifdef USE_INSTANCING
	mvPosition = instanceMatrix * mvPosition;
#endif
mvPosition = modelViewMatrix * mvPosition;
gl_Position = projectionMatrix * mvPosition;`, Ru = `#ifdef DITHERING
	gl_FragColor.rgb = dithering( gl_FragColor.rgb );
#endif`, Pu = `#ifdef DITHERING
	vec3 dithering( vec3 color ) {
		float grid_position = rand( gl_FragCoord.xy );
		vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
		dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
		return color + dither_shift_RGB;
	}
#endif`, Uu = `float roughnessFactor = roughness;
#ifdef USE_ROUGHNESSMAP
	vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );
	roughnessFactor *= texelRoughness.g;
#endif`, Du = `#ifdef USE_ROUGHNESSMAP
	uniform sampler2D roughnessMap;
#endif`, Lu = `#if NUM_SPOT_LIGHT_COORDS > 0
	varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
#endif
#if NUM_SPOT_LIGHT_MAPS > 0
	uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];
#endif
#ifdef USE_SHADOWMAP
	#if NUM_DIR_LIGHT_SHADOWS > 0
		uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
		varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
		struct DirectionalLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
		};
		uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
	#endif
	#if NUM_SPOT_LIGHT_SHADOWS > 0
		uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
		struct SpotLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
		};
		uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
	#endif
	#if NUM_POINT_LIGHT_SHADOWS > 0
		uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
		varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
		struct PointLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
			float shadowCameraNear;
			float shadowCameraFar;
		};
		uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
	#endif
	float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
		return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );
	}
	vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {
		return unpackRGBATo2Half( texture2D( shadow, uv ) );
	}
	float VSMShadow (sampler2D shadow, vec2 uv, float compare ){
		float occlusion = 1.0;
		vec2 distribution = texture2DDistribution( shadow, uv );
		float hard_shadow = step( compare , distribution.x );
		if (hard_shadow != 1.0 ) {
			float distance = compare - distribution.x ;
			float variance = max( 0.00000, distribution.y * distribution.y );
			float softness_probability = variance / (variance + distance * distance );			softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );			occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );
		}
		return occlusion;
	}
	float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
		float shadow = 1.0;
		shadowCoord.xyz /= shadowCoord.w;
		shadowCoord.z += shadowBias;
		bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
		bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
		if ( frustumTest ) {
		#if defined( SHADOWMAP_TYPE_PCF )
			vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
			float dx0 = - texelSize.x * shadowRadius;
			float dy0 = - texelSize.y * shadowRadius;
			float dx1 = + texelSize.x * shadowRadius;
			float dy1 = + texelSize.y * shadowRadius;
			float dx2 = dx0 / 2.0;
			float dy2 = dy0 / 2.0;
			float dx3 = dx1 / 2.0;
			float dy3 = dy1 / 2.0;
			shadow = (
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )
			) * ( 1.0 / 17.0 );
		#elif defined( SHADOWMAP_TYPE_PCF_SOFT )
			vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
			float dx = texelSize.x;
			float dy = texelSize.y;
			vec2 uv = shadowCoord.xy;
			vec2 f = fract( uv * shadowMapSize + 0.5 );
			uv -= f * texelSize;
			shadow = (
				texture2DCompare( shadowMap, uv, shadowCoord.z ) +
				texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
				texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
				mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),
					 texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
					 f.x ) +
				mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),
					 texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
					 f.x ) +
				mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),
					 texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
					 f.y ) +
				mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),
					 texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
					 f.y ) +
				mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),
						  texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
						  f.x ),
					 mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),
						  texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
						  f.x ),
					 f.y )
			) * ( 1.0 / 9.0 );
		#elif defined( SHADOWMAP_TYPE_VSM )
			shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );
		#else
			shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );
		#endif
		}
		return mix( 1.0, shadow, shadowIntensity );
	}
	vec2 cubeToUV( vec3 v, float texelSizeY ) {
		vec3 absV = abs( v );
		float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );
		absV *= scaleToCube;
		v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );
		vec2 planar = v.xy;
		float almostATexel = 1.5 * texelSizeY;
		float almostOne = 1.0 - almostATexel;
		if ( absV.z >= almostOne ) {
			if ( v.z > 0.0 )
				planar.x = 4.0 - v.x;
		} else if ( absV.x >= almostOne ) {
			float signX = sign( v.x );
			planar.x = v.z * signX + 2.0 * signX;
		} else if ( absV.y >= almostOne ) {
			float signY = sign( v.y );
			planar.x = v.x + 2.0 * signY + 2.0;
			planar.y = v.z * signY - 2.0;
		}
		return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );
	}
	float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
		float shadow = 1.0;
		vec3 lightToPosition = shadowCoord.xyz;
		
		float lightToPositionLength = length( lightToPosition );
		if ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {
			float dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );			dp += shadowBias;
			vec3 bd3D = normalize( lightToPosition );
			vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
			#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )
				vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
				shadow = (
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )
				) * ( 1.0 / 9.0 );
			#else
				shadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
			#endif
		}
		return mix( 1.0, shadow, shadowIntensity );
	}
#endif`, Fu = `#if NUM_SPOT_LIGHT_COORDS > 0
	uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];
	varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
#endif
#ifdef USE_SHADOWMAP
	#if NUM_DIR_LIGHT_SHADOWS > 0
		uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];
		varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
		struct DirectionalLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
		};
		uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
	#endif
	#if NUM_SPOT_LIGHT_SHADOWS > 0
		struct SpotLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
		};
		uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
	#endif
	#if NUM_POINT_LIGHT_SHADOWS > 0
		uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];
		varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
		struct PointLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
			float shadowCameraNear;
			float shadowCameraFar;
		};
		uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
	#endif
#endif`, Iu = `#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
	vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
	vec4 shadowWorldPosition;
#endif
#if defined( USE_SHADOWMAP )
	#if NUM_DIR_LIGHT_SHADOWS > 0
		#pragma unroll_loop_start
		for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
			shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );
			vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;
		}
		#pragma unroll_loop_end
	#endif
	#if NUM_POINT_LIGHT_SHADOWS > 0
		#pragma unroll_loop_start
		for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
			shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );
			vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;
		}
		#pragma unroll_loop_end
	#endif
#endif
#if NUM_SPOT_LIGHT_COORDS > 0
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {
		shadowWorldPosition = worldPosition;
		#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
			shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;
		#endif
		vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;
	}
	#pragma unroll_loop_end
#endif`, Nu = `float getShadowMask() {
	float shadow = 1.0;
	#ifdef USE_SHADOWMAP
	#if NUM_DIR_LIGHT_SHADOWS > 0
	DirectionalLightShadow directionalLight;
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
		directionalLight = directionalLightShadows[ i ];
		shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
	}
	#pragma unroll_loop_end
	#endif
	#if NUM_SPOT_LIGHT_SHADOWS > 0
	SpotLightShadow spotLight;
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
		spotLight = spotLightShadows[ i ];
		shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
	}
	#pragma unroll_loop_end
	#endif
	#if NUM_POINT_LIGHT_SHADOWS > 0
	PointLightShadow pointLight;
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
		pointLight = pointLightShadows[ i ];
		shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
	}
	#pragma unroll_loop_end
	#endif
	#endif
	return shadow;
}`, Ou = `#ifdef USE_SKINNING
	mat4 boneMatX = getBoneMatrix( skinIndex.x );
	mat4 boneMatY = getBoneMatrix( skinIndex.y );
	mat4 boneMatZ = getBoneMatrix( skinIndex.z );
	mat4 boneMatW = getBoneMatrix( skinIndex.w );
#endif`, Bu = `#ifdef USE_SKINNING
	uniform mat4 bindMatrix;
	uniform mat4 bindMatrixInverse;
	uniform highp sampler2D boneTexture;
	mat4 getBoneMatrix( const in float i ) {
		int size = textureSize( boneTexture, 0 ).x;
		int j = int( i ) * 4;
		int x = j % size;
		int y = j / size;
		vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );
		vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );
		vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );
		vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );
		return mat4( v1, v2, v3, v4 );
	}
#endif`, ku = `#ifdef USE_SKINNING
	vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
	vec4 skinned = vec4( 0.0 );
	skinned += boneMatX * skinVertex * skinWeight.x;
	skinned += boneMatY * skinVertex * skinWeight.y;
	skinned += boneMatZ * skinVertex * skinWeight.z;
	skinned += boneMatW * skinVertex * skinWeight.w;
	transformed = ( bindMatrixInverse * skinned ).xyz;
#endif`, Gu = `#ifdef USE_SKINNING
	mat4 skinMatrix = mat4( 0.0 );
	skinMatrix += skinWeight.x * boneMatX;
	skinMatrix += skinWeight.y * boneMatY;
	skinMatrix += skinWeight.z * boneMatZ;
	skinMatrix += skinWeight.w * boneMatW;
	skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
	objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;
	#ifdef USE_TANGENT
		objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;
	#endif
#endif`, zu = `float specularStrength;
#ifdef USE_SPECULARMAP
	vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );
	specularStrength = texelSpecular.r;
#else
	specularStrength = 1.0;
#endif`, Vu = `#ifdef USE_SPECULARMAP
	uniform sampler2D specularMap;
#endif`, Hu = `#if defined( TONE_MAPPING )
	gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
#endif`, Wu = `#ifndef saturate
#define saturate( a ) clamp( a, 0.0, 1.0 )
#endif
uniform float toneMappingExposure;
vec3 LinearToneMapping( vec3 color ) {
	return saturate( toneMappingExposure * color );
}
vec3 ReinhardToneMapping( vec3 color ) {
	color *= toneMappingExposure;
	return saturate( color / ( vec3( 1.0 ) + color ) );
}
vec3 CineonToneMapping( vec3 color ) {
	color *= toneMappingExposure;
	color = max( vec3( 0.0 ), color - 0.004 );
	return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
}
vec3 RRTAndODTFit( vec3 v ) {
	vec3 a = v * ( v + 0.0245786 ) - 0.000090537;
	vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;
	return a / b;
}
vec3 ACESFilmicToneMapping( vec3 color ) {
	const mat3 ACESInputMat = mat3(
		vec3( 0.59719, 0.07600, 0.02840 ),		vec3( 0.35458, 0.90834, 0.13383 ),
		vec3( 0.04823, 0.01566, 0.83777 )
	);
	const mat3 ACESOutputMat = mat3(
		vec3(  1.60475, -0.10208, -0.00327 ),		vec3( -0.53108,  1.10813, -0.07276 ),
		vec3( -0.07367, -0.00605,  1.07602 )
	);
	color *= toneMappingExposure / 0.6;
	color = ACESInputMat * color;
	color = RRTAndODTFit( color );
	color = ACESOutputMat * color;
	return saturate( color );
}
const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(
	vec3( 1.6605, - 0.1246, - 0.0182 ),
	vec3( - 0.5876, 1.1329, - 0.1006 ),
	vec3( - 0.0728, - 0.0083, 1.1187 )
);
const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(
	vec3( 0.6274, 0.0691, 0.0164 ),
	vec3( 0.3293, 0.9195, 0.0880 ),
	vec3( 0.0433, 0.0113, 0.8956 )
);
vec3 agxDefaultContrastApprox( vec3 x ) {
	vec3 x2 = x * x;
	vec3 x4 = x2 * x2;
	return + 15.5 * x4 * x2
		- 40.14 * x4 * x
		+ 31.96 * x4
		- 6.868 * x2 * x
		+ 0.4298 * x2
		+ 0.1191 * x
		- 0.00232;
}
vec3 AgXToneMapping( vec3 color ) {
	const mat3 AgXInsetMatrix = mat3(
		vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),
		vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),
		vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )
	);
	const mat3 AgXOutsetMatrix = mat3(
		vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),
		vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),
		vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )
	);
	const float AgxMinEv = - 12.47393;	const float AgxMaxEv = 4.026069;
	color *= toneMappingExposure;
	color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;
	color = AgXInsetMatrix * color;
	color = max( color, 1e-10 );	color = log2( color );
	color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );
	color = clamp( color, 0.0, 1.0 );
	color = agxDefaultContrastApprox( color );
	color = AgXOutsetMatrix * color;
	color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );
	color = LINEAR_REC2020_TO_LINEAR_SRGB * color;
	color = clamp( color, 0.0, 1.0 );
	return color;
}
vec3 NeutralToneMapping( vec3 color ) {
	const float StartCompression = 0.8 - 0.04;
	const float Desaturation = 0.15;
	color *= toneMappingExposure;
	float x = min( color.r, min( color.g, color.b ) );
	float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
	color -= offset;
	float peak = max( color.r, max( color.g, color.b ) );
	if ( peak < StartCompression ) return color;
	float d = 1. - StartCompression;
	float newPeak = 1. - d * d / ( peak + d - StartCompression );
	color *= newPeak / peak;
	float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );
	return mix( color, vec3( newPeak ), g );
}
vec3 CustomToneMapping( vec3 color ) { return color; }`, Xu = `#ifdef USE_TRANSMISSION
	material.transmission = transmission;
	material.transmissionAlpha = 1.0;
	material.thickness = thickness;
	material.attenuationDistance = attenuationDistance;
	material.attenuationColor = attenuationColor;
	#ifdef USE_TRANSMISSIONMAP
		material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;
	#endif
	#ifdef USE_THICKNESSMAP
		material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;
	#endif
	vec3 pos = vWorldPosition;
	vec3 v = normalize( cameraPosition - pos );
	vec3 n = inverseTransformDirection( normal, viewMatrix );
	vec4 transmitted = getIBLVolumeRefraction(
		n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,
		pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,
		material.attenuationColor, material.attenuationDistance );
	material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );
	totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );
#endif`, qu = `#ifdef USE_TRANSMISSION
	uniform float transmission;
	uniform float thickness;
	uniform float attenuationDistance;
	uniform vec3 attenuationColor;
	#ifdef USE_TRANSMISSIONMAP
		uniform sampler2D transmissionMap;
	#endif
	#ifdef USE_THICKNESSMAP
		uniform sampler2D thicknessMap;
	#endif
	uniform vec2 transmissionSamplerSize;
	uniform sampler2D transmissionSamplerMap;
	uniform mat4 modelMatrix;
	uniform mat4 projectionMatrix;
	varying vec3 vWorldPosition;
	float w0( float a ) {
		return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );
	}
	float w1( float a ) {
		return ( 1.0 / 6.0 ) * ( a *  a * ( 3.0 * a - 6.0 ) + 4.0 );
	}
	float w2( float a ){
		return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );
	}
	float w3( float a ) {
		return ( 1.0 / 6.0 ) * ( a * a * a );
	}
	float g0( float a ) {
		return w0( a ) + w1( a );
	}
	float g1( float a ) {
		return w2( a ) + w3( a );
	}
	float h0( float a ) {
		return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );
	}
	float h1( float a ) {
		return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );
	}
	vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {
		uv = uv * texelSize.zw + 0.5;
		vec2 iuv = floor( uv );
		vec2 fuv = fract( uv );
		float g0x = g0( fuv.x );
		float g1x = g1( fuv.x );
		float h0x = h0( fuv.x );
		float h1x = h1( fuv.x );
		float h0y = h0( fuv.y );
		float h1y = h1( fuv.y );
		vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
		vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
		vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
		vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
		return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +
			g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );
	}
	vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {
		vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );
		vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );
		vec2 fLodSizeInv = 1.0 / fLodSize;
		vec2 cLodSizeInv = 1.0 / cLodSize;
		vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );
		vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );
		return mix( fSample, cSample, fract( lod ) );
	}
	vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {
		vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
		vec3 modelScale;
		modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
		modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
		modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
		return normalize( refractionVector ) * thickness * modelScale;
	}
	float applyIorToRoughness( const in float roughness, const in float ior ) {
		return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
	}
	vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {
		float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
		return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );
	}
	vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
		if ( isinf( attenuationDistance ) ) {
			return vec3( 1.0 );
		} else {
			vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
			vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );			return transmittance;
		}
	}
	vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
		const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
		const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,
		const in vec3 attenuationColor, const in float attenuationDistance ) {
		vec4 transmittedLight;
		vec3 transmittance;
		#ifdef USE_DISPERSION
			float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;
			vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );
			for ( int i = 0; i < 3; i ++ ) {
				vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );
				vec3 refractedRayExit = position + transmissionRay;
		
				vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
				vec2 refractionCoords = ndcPos.xy / ndcPos.w;
				refractionCoords += 1.0;
				refractionCoords /= 2.0;
		
				vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );
				transmittedLight[ i ] = transmissionSample[ i ];
				transmittedLight.a += transmissionSample.a;
				transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];
			}
			transmittedLight.a /= 3.0;
		
		#else
		
			vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
			vec3 refractedRayExit = position + transmissionRay;
			vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
			vec2 refractionCoords = ndcPos.xy / ndcPos.w;
			refractionCoords += 1.0;
			refractionCoords /= 2.0;
			transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
			transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );
		
		#endif
		vec3 attenuatedColor = transmittance * transmittedLight.rgb;
		vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
		float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;
		return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );
	}
#endif`, Yu = `#if defined( USE_UV ) || defined( USE_ANISOTROPY )
	varying vec2 vUv;
#endif
#ifdef USE_MAP
	varying vec2 vMapUv;
#endif
#ifdef USE_ALPHAMAP
	varying vec2 vAlphaMapUv;
#endif
#ifdef USE_LIGHTMAP
	varying vec2 vLightMapUv;
#endif
#ifdef USE_AOMAP
	varying vec2 vAoMapUv;
#endif
#ifdef USE_BUMPMAP
	varying vec2 vBumpMapUv;
#endif
#ifdef USE_NORMALMAP
	varying vec2 vNormalMapUv;
#endif
#ifdef USE_EMISSIVEMAP
	varying vec2 vEmissiveMapUv;
#endif
#ifdef USE_METALNESSMAP
	varying vec2 vMetalnessMapUv;
#endif
#ifdef USE_ROUGHNESSMAP
	varying vec2 vRoughnessMapUv;
#endif
#ifdef USE_ANISOTROPYMAP
	varying vec2 vAnisotropyMapUv;
#endif
#ifdef USE_CLEARCOATMAP
	varying vec2 vClearcoatMapUv;
#endif
#ifdef USE_CLEARCOAT_NORMALMAP
	varying vec2 vClearcoatNormalMapUv;
#endif
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
	varying vec2 vClearcoatRoughnessMapUv;
#endif
#ifdef USE_IRIDESCENCEMAP
	varying vec2 vIridescenceMapUv;
#endif
#ifdef USE_IRIDESCENCE_THICKNESSMAP
	varying vec2 vIridescenceThicknessMapUv;
#endif
#ifdef USE_SHEEN_COLORMAP
	varying vec2 vSheenColorMapUv;
#endif
#ifdef USE_SHEEN_ROUGHNESSMAP
	varying vec2 vSheenRoughnessMapUv;
#endif
#ifdef USE_SPECULARMAP
	varying vec2 vSpecularMapUv;
#endif
#ifdef USE_SPECULAR_COLORMAP
	varying vec2 vSpecularColorMapUv;
#endif
#ifdef USE_SPECULAR_INTENSITYMAP
	varying vec2 vSpecularIntensityMapUv;
#endif
#ifdef USE_TRANSMISSIONMAP
	uniform mat3 transmissionMapTransform;
	varying vec2 vTransmissionMapUv;
#endif
#ifdef USE_THICKNESSMAP
	uniform mat3 thicknessMapTransform;
	varying vec2 vThicknessMapUv;
#endif`, ju = `#if defined( USE_UV ) || defined( USE_ANISOTROPY )
	varying vec2 vUv;
#endif
#ifdef USE_MAP
	uniform mat3 mapTransform;
	varying vec2 vMapUv;
#endif
#ifdef USE_ALPHAMAP
	uniform mat3 alphaMapTransform;
	varying vec2 vAlphaMapUv;
#endif
#ifdef USE_LIGHTMAP
	uniform mat3 lightMapTransform;
	varying vec2 vLightMapUv;
#endif
#ifdef USE_AOMAP
	uniform mat3 aoMapTransform;
	varying vec2 vAoMapUv;
#endif
#ifdef USE_BUMPMAP
	uniform mat3 bumpMapTransform;
	varying vec2 vBumpMapUv;
#endif
#ifdef USE_NORMALMAP
	uniform mat3 normalMapTransform;
	varying vec2 vNormalMapUv;
#endif
#ifdef USE_DISPLACEMENTMAP
	uniform mat3 displacementMapTransform;
	varying vec2 vDisplacementMapUv;
#endif
#ifdef USE_EMISSIVEMAP
	uniform mat3 emissiveMapTransform;
	varying vec2 vEmissiveMapUv;
#endif
#ifdef USE_METALNESSMAP
	uniform mat3 metalnessMapTransform;
	varying vec2 vMetalnessMapUv;
#endif
#ifdef USE_ROUGHNESSMAP
	uniform mat3 roughnessMapTransform;
	varying vec2 vRoughnessMapUv;
#endif
#ifdef USE_ANISOTROPYMAP
	uniform mat3 anisotropyMapTransform;
	varying vec2 vAnisotropyMapUv;
#endif
#ifdef USE_CLEARCOATMAP
	uniform mat3 clearcoatMapTransform;
	varying vec2 vClearcoatMapUv;
#endif
#ifdef USE_CLEARCOAT_NORMALMAP
	uniform mat3 clearcoatNormalMapTransform;
	varying vec2 vClearcoatNormalMapUv;
#endif
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
	uniform mat3 clearcoatRoughnessMapTransform;
	varying vec2 vClearcoatRoughnessMapUv;
#endif
#ifdef USE_SHEEN_COLORMAP
	uniform mat3 sheenColorMapTransform;
	varying vec2 vSheenColorMapUv;
#endif
#ifdef USE_SHEEN_ROUGHNESSMAP
	uniform mat3 sheenRoughnessMapTransform;
	varying vec2 vSheenRoughnessMapUv;
#endif
#ifdef USE_IRIDESCENCEMAP
	uniform mat3 iridescenceMapTransform;
	varying vec2 vIridescenceMapUv;
#endif
#ifdef USE_IRIDESCENCE_THICKNESSMAP
	uniform mat3 iridescenceThicknessMapTransform;
	varying vec2 vIridescenceThicknessMapUv;
#endif
#ifdef USE_SPECULARMAP
	uniform mat3 specularMapTransform;
	varying vec2 vSpecularMapUv;
#endif
#ifdef USE_SPECULAR_COLORMAP
	uniform mat3 specularColorMapTransform;
	varying vec2 vSpecularColorMapUv;
#endif
#ifdef USE_SPECULAR_INTENSITYMAP
	uniform mat3 specularIntensityMapTransform;
	varying vec2 vSpecularIntensityMapUv;
#endif
#ifdef USE_TRANSMISSIONMAP
	uniform mat3 transmissionMapTransform;
	varying vec2 vTransmissionMapUv;
#endif
#ifdef USE_THICKNESSMAP
	uniform mat3 thicknessMapTransform;
	varying vec2 vThicknessMapUv;
#endif`, Zu = `#if defined( USE_UV ) || defined( USE_ANISOTROPY )
	vUv = vec3( uv, 1 ).xy;
#endif
#ifdef USE_MAP
	vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;
#endif
#ifdef USE_ALPHAMAP
	vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_LIGHTMAP
	vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_AOMAP
	vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_BUMPMAP
	vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_NORMALMAP
	vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_DISPLACEMENTMAP
	vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_EMISSIVEMAP
	vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_METALNESSMAP
	vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_ROUGHNESSMAP
	vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_ANISOTROPYMAP
	vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_CLEARCOATMAP
	vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_CLEARCOAT_NORMALMAP
	vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
	vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_IRIDESCENCEMAP
	vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_IRIDESCENCE_THICKNESSMAP
	vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_SHEEN_COLORMAP
	vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_SHEEN_ROUGHNESSMAP
	vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_SPECULARMAP
	vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_SPECULAR_COLORMAP
	vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_SPECULAR_INTENSITYMAP
	vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_TRANSMISSIONMAP
	vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_THICKNESSMAP
	vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;
#endif`, Ku = `#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0
	vec4 worldPosition = vec4( transformed, 1.0 );
	#ifdef USE_BATCHING
		worldPosition = batchingMatrix * worldPosition;
	#endif
	#ifdef USE_INSTANCING
		worldPosition = instanceMatrix * worldPosition;
	#endif
	worldPosition = modelMatrix * worldPosition;
#endif`;
const Ju = `varying vec2 vUv;
uniform mat3 uvTransform;
void main() {
	vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
	gl_Position = vec4( position.xy, 1.0, 1.0 );
}`, Qu = `uniform sampler2D t2D;
uniform float backgroundIntensity;
varying vec2 vUv;
void main() {
	vec4 texColor = texture2D( t2D, vUv );
	#ifdef DECODE_VIDEO_TEXTURE
		texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );
	#endif
	texColor.rgb *= backgroundIntensity;
	gl_FragColor = texColor;
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
}`, $u = `varying vec3 vWorldDirection;
#include <common>
void main() {
	vWorldDirection = transformDirection( position, modelMatrix );
	#include <begin_vertex>
	#include <project_vertex>
	gl_Position.z = gl_Position.w;
}`, eh = `#ifdef ENVMAP_TYPE_CUBE
	uniform samplerCube envMap;
#elif defined( ENVMAP_TYPE_CUBE_UV )
	uniform sampler2D envMap;
#endif
uniform float flipEnvMap;
uniform float backgroundBlurriness;
uniform float backgroundIntensity;
uniform mat3 backgroundRotation;
varying vec3 vWorldDirection;
#include <cube_uv_reflection_fragment>
void main() {
	#ifdef ENVMAP_TYPE_CUBE
		vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );
	#elif defined( ENVMAP_TYPE_CUBE_UV )
		vec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );
	#else
		vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );
	#endif
	texColor.rgb *= backgroundIntensity;
	gl_FragColor = texColor;
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
}`, th = `varying vec3 vWorldDirection;
#include <common>
void main() {
	vWorldDirection = transformDirection( position, modelMatrix );
	#include <begin_vertex>
	#include <project_vertex>
	gl_Position.z = gl_Position.w;
}`, nh = `uniform samplerCube tCube;
uniform float tFlip;
uniform float opacity;
varying vec3 vWorldDirection;
void main() {
	vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );
	gl_FragColor = texColor;
	gl_FragColor.a *= opacity;
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
}`, ih = `#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
varying vec2 vHighPrecisionZW;
void main() {
	#include <uv_vertex>
	#include <batching_vertex>
	#include <skinbase_vertex>
	#include <morphinstance_vertex>
	#ifdef USE_DISPLACEMENTMAP
		#include <beginnormal_vertex>
		#include <morphnormal_vertex>
		#include <skinnormal_vertex>
	#endif
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	vHighPrecisionZW = gl_Position.zw;
}`, rh = `#if DEPTH_PACKING == 3200
	uniform float opacity;
#endif
#include <common>
#include <packing>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
varying vec2 vHighPrecisionZW;
void main() {
	vec4 diffuseColor = vec4( 1.0 );
	#include <clipping_planes_fragment>
	#if DEPTH_PACKING == 3200
		diffuseColor.a = opacity;
	#endif
	#include <map_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <logdepthbuf_fragment>
	float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
	#if DEPTH_PACKING == 3200
		gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
	#elif DEPTH_PACKING == 3201
		gl_FragColor = packDepthToRGBA( fragCoordZ );
	#elif DEPTH_PACKING == 3202
		gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );
	#elif DEPTH_PACKING == 3203
		gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );
	#endif
}`, ah = `#define DISTANCE
varying vec3 vWorldPosition;
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <batching_vertex>
	#include <skinbase_vertex>
	#include <morphinstance_vertex>
	#ifdef USE_DISPLACEMENTMAP
		#include <beginnormal_vertex>
		#include <morphnormal_vertex>
		#include <skinnormal_vertex>
	#endif
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <worldpos_vertex>
	#include <clipping_planes_vertex>
	vWorldPosition = worldPosition.xyz;
}`, sh = `#define DISTANCE
uniform vec3 referencePosition;
uniform float nearDistance;
uniform float farDistance;
varying vec3 vWorldPosition;
#include <common>
#include <packing>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <clipping_planes_pars_fragment>
void main () {
	vec4 diffuseColor = vec4( 1.0 );
	#include <clipping_planes_fragment>
	#include <map_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	float dist = length( vWorldPosition - referencePosition );
	dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
	dist = saturate( dist );
	gl_FragColor = packDepthToRGBA( dist );
}`, oh = `varying vec3 vWorldDirection;
#include <common>
void main() {
	vWorldDirection = transformDirection( position, modelMatrix );
	#include <begin_vertex>
	#include <project_vertex>
}`, lh = `uniform sampler2D tEquirect;
varying vec3 vWorldDirection;
#include <common>
void main() {
	vec3 direction = normalize( vWorldDirection );
	vec2 sampleUV = equirectUv( direction );
	gl_FragColor = texture2D( tEquirect, sampleUV );
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
}`, ch = `uniform float scale;
attribute float lineDistance;
varying float vLineDistance;
#include <common>
#include <uv_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	vLineDistance = scale * lineDistance;
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	#include <fog_vertex>
}`, uh = `uniform vec3 diffuse;
uniform float opacity;
uniform float dashSize;
uniform float totalSize;
varying float vLineDistance;
#include <common>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	if ( mod( vLineDistance, totalSize ) > dashSize ) {
		discard;
	}
	vec3 outgoingLight = vec3( 0.0 );
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	outgoingLight = diffuseColor.rgb;
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
}`, hh = `#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <envmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )
		#include <beginnormal_vertex>
		#include <morphnormal_vertex>
		#include <skinbase_vertex>
		#include <skinnormal_vertex>
		#include <defaultnormal_vertex>
	#endif
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	#include <worldpos_vertex>
	#include <envmap_vertex>
	#include <fog_vertex>
}`, fh = `uniform vec3 diffuse;
uniform float opacity;
#ifndef FLAT_SHADED
	varying vec3 vNormal;
#endif
#include <common>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_pars_fragment>
#include <fog_pars_fragment>
#include <specularmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <specularmap_fragment>
	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
	#ifdef USE_LIGHTMAP
		vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
		reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;
	#else
		reflectedLight.indirectDiffuse += vec3( 1.0 );
	#endif
	#include <aomap_fragment>
	reflectedLight.indirectDiffuse *= diffuseColor.rgb;
	vec3 outgoingLight = reflectedLight.indirectDiffuse;
	#include <envmap_fragment>
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, dh = `#define LAMBERT
varying vec3 vViewPosition;
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <envmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	vViewPosition = - mvPosition.xyz;
	#include <worldpos_vertex>
	#include <envmap_vertex>
	#include <shadowmap_vertex>
	#include <fog_vertex>
}`, ph = `#define LAMBERT
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float opacity;
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_pars_fragment>
#include <fog_pars_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <normal_pars_fragment>
#include <lights_lambert_pars_fragment>
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <specularmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
	vec3 totalEmissiveRadiance = emissive;
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <specularmap_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	#include <emissivemap_fragment>
	#include <lights_lambert_fragment>
	#include <lights_fragment_begin>
	#include <lights_fragment_maps>
	#include <lights_fragment_end>
	#include <aomap_fragment>
	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
	#include <envmap_fragment>
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, mh = `#define MATCAP
varying vec3 vViewPosition;
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <color_pars_vertex>
#include <displacementmap_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	#include <fog_vertex>
	vViewPosition = - mvPosition.xyz;
}`, gh = `#define MATCAP
uniform vec3 diffuse;
uniform float opacity;
uniform sampler2D matcap;
varying vec3 vViewPosition;
#include <common>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <fog_pars_fragment>
#include <normal_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	vec3 viewDir = normalize( vViewPosition );
	vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );
	vec3 y = cross( viewDir, x );
	vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;
	#ifdef USE_MATCAP
		vec4 matcapColor = texture2D( matcap, uv );
	#else
		vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );
	#endif
	vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, vh = `#define NORMAL
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
	varying vec3 vViewPosition;
#endif
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphinstance_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
	vViewPosition = - mvPosition.xyz;
#endif
}`, _h = `#define NORMAL
uniform float opacity;
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
	varying vec3 vViewPosition;
#endif
#include <packing>
#include <uv_pars_fragment>
#include <normal_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );
	#include <clipping_planes_fragment>
	#include <logdepthbuf_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	gl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a );
	#ifdef OPAQUE
		gl_FragColor.a = 1.0;
	#endif
}`, xh = `#define PHONG
varying vec3 vViewPosition;
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <envmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphinstance_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	vViewPosition = - mvPosition.xyz;
	#include <worldpos_vertex>
	#include <envmap_vertex>
	#include <shadowmap_vertex>
	#include <fog_vertex>
}`, Sh = `#define PHONG
uniform vec3 diffuse;
uniform vec3 emissive;
uniform vec3 specular;
uniform float shininess;
uniform float opacity;
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_pars_fragment>
#include <fog_pars_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <normal_pars_fragment>
#include <lights_phong_pars_fragment>
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <specularmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
	vec3 totalEmissiveRadiance = emissive;
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <specularmap_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	#include <emissivemap_fragment>
	#include <lights_phong_fragment>
	#include <lights_fragment_begin>
	#include <lights_fragment_maps>
	#include <lights_fragment_end>
	#include <aomap_fragment>
	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
	#include <envmap_fragment>
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, yh = `#define STANDARD
varying vec3 vViewPosition;
#ifdef USE_TRANSMISSION
	varying vec3 vWorldPosition;
#endif
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	vViewPosition = - mvPosition.xyz;
	#include <worldpos_vertex>
	#include <shadowmap_vertex>
	#include <fog_vertex>
#ifdef USE_TRANSMISSION
	vWorldPosition = worldPosition.xyz;
#endif
}`, Mh = `#define STANDARD
#ifdef PHYSICAL
	#define IOR
	#define USE_SPECULAR
#endif
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float roughness;
uniform float metalness;
uniform float opacity;
#ifdef IOR
	uniform float ior;
#endif
#ifdef USE_SPECULAR
	uniform float specularIntensity;
	uniform vec3 specularColor;
	#ifdef USE_SPECULAR_COLORMAP
		uniform sampler2D specularColorMap;
	#endif
	#ifdef USE_SPECULAR_INTENSITYMAP
		uniform sampler2D specularIntensityMap;
	#endif
#endif
#ifdef USE_CLEARCOAT
	uniform float clearcoat;
	uniform float clearcoatRoughness;
#endif
#ifdef USE_DISPERSION
	uniform float dispersion;
#endif
#ifdef USE_IRIDESCENCE
	uniform float iridescence;
	uniform float iridescenceIOR;
	uniform float iridescenceThicknessMinimum;
	uniform float iridescenceThicknessMaximum;
#endif
#ifdef USE_SHEEN
	uniform vec3 sheenColor;
	uniform float sheenRoughness;
	#ifdef USE_SHEEN_COLORMAP
		uniform sampler2D sheenColorMap;
	#endif
	#ifdef USE_SHEEN_ROUGHNESSMAP
		uniform sampler2D sheenRoughnessMap;
	#endif
#endif
#ifdef USE_ANISOTROPY
	uniform vec2 anisotropyVector;
	#ifdef USE_ANISOTROPYMAP
		uniform sampler2D anisotropyMap;
	#endif
#endif
varying vec3 vViewPosition;
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <iridescence_fragment>
#include <cube_uv_reflection_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_physical_pars_fragment>
#include <fog_pars_fragment>
#include <lights_pars_begin>
#include <normal_pars_fragment>
#include <lights_physical_pars_fragment>
#include <transmission_pars_fragment>
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <clearcoat_pars_fragment>
#include <iridescence_pars_fragment>
#include <roughnessmap_pars_fragment>
#include <metalnessmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
	vec3 totalEmissiveRadiance = emissive;
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <roughnessmap_fragment>
	#include <metalnessmap_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	#include <clearcoat_normal_fragment_begin>
	#include <clearcoat_normal_fragment_maps>
	#include <emissivemap_fragment>
	#include <lights_physical_fragment>
	#include <lights_fragment_begin>
	#include <lights_fragment_maps>
	#include <lights_fragment_end>
	#include <aomap_fragment>
	vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
	vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
	#include <transmission_fragment>
	vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
	#ifdef USE_SHEEN
		float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
		outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;
	#endif
	#ifdef USE_CLEARCOAT
		float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
		vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
		outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
	#endif
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, Eh = `#define TOON
varying vec3 vViewPosition;
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	vViewPosition = - mvPosition.xyz;
	#include <worldpos_vertex>
	#include <shadowmap_vertex>
	#include <fog_vertex>
}`, Th = `#define TOON
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float opacity;
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <gradientmap_pars_fragment>
#include <fog_pars_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <normal_pars_fragment>
#include <lights_toon_pars_fragment>
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
	vec3 totalEmissiveRadiance = emissive;
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	#include <emissivemap_fragment>
	#include <lights_toon_fragment>
	#include <lights_fragment_begin>
	#include <lights_fragment_maps>
	#include <lights_fragment_end>
	#include <aomap_fragment>
	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, bh = `uniform float size;
uniform float scale;
#include <common>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
#ifdef USE_POINTS_UV
	varying vec2 vUv;
	uniform mat3 uvTransform;
#endif
void main() {
	#ifdef USE_POINTS_UV
		vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
	#endif
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <project_vertex>
	gl_PointSize = size;
	#ifdef USE_SIZEATTENUATION
		bool isPerspective = isPerspectiveMatrix( projectionMatrix );
		if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );
	#endif
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	#include <worldpos_vertex>
	#include <fog_vertex>
}`, Ah = `uniform vec3 diffuse;
uniform float opacity;
#include <common>
#include <color_pars_fragment>
#include <map_particle_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	vec3 outgoingLight = vec3( 0.0 );
	#include <logdepthbuf_fragment>
	#include <map_particle_fragment>
	#include <color_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	outgoingLight = diffuseColor.rgb;
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
}`, wh = `#include <common>
#include <batching_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <shadowmap_pars_vertex>
void main() {
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphinstance_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <worldpos_vertex>
	#include <shadowmap_vertex>
	#include <fog_vertex>
}`, Ch = `uniform vec3 color;
uniform float opacity;
#include <common>
#include <packing>
#include <fog_pars_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <logdepthbuf_pars_fragment>
#include <shadowmap_pars_fragment>
#include <shadowmask_pars_fragment>
void main() {
	#include <logdepthbuf_fragment>
	gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
}`, Rh = `uniform float rotation;
uniform vec2 center;
#include <common>
#include <uv_pars_vertex>
#include <fog_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	vec4 mvPosition = modelViewMatrix[ 3 ];
	vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );
	#ifndef USE_SIZEATTENUATION
		bool isPerspective = isPerspectiveMatrix( projectionMatrix );
		if ( isPerspective ) scale *= - mvPosition.z;
	#endif
	vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;
	vec2 rotatedPosition;
	rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
	rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
	mvPosition.xy += rotatedPosition;
	gl_Position = projectionMatrix * mvPosition;
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	#include <fog_vertex>
}`, Ph = `uniform vec3 diffuse;
uniform float opacity;
#include <common>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	vec3 outgoingLight = vec3( 0.0 );
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	outgoingLight = diffuseColor.rgb;
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
}`, Xe = {
  alphahash_fragment: Ql,
  alphahash_pars_fragment: $l,
  alphamap_fragment: ec,
  alphamap_pars_fragment: tc,
  alphatest_fragment: nc,
  alphatest_pars_fragment: ic,
  aomap_fragment: rc,
  aomap_pars_fragment: ac,
  batching_pars_vertex: sc,
  batching_vertex: oc,
  begin_vertex: lc,
  beginnormal_vertex: cc,
  bsdfs: uc,
  iridescence_fragment: hc,
  bumpmap_pars_fragment: fc,
  clipping_planes_fragment: dc,
  clipping_planes_pars_fragment: pc,
  clipping_planes_pars_vertex: mc,
  clipping_planes_vertex: gc,
  color_fragment: vc,
  color_pars_fragment: _c,
  color_pars_vertex: xc,
  color_vertex: Sc,
  common: yc,
  cube_uv_reflection_fragment: Mc,
  defaultnormal_vertex: Ec,
  displacementmap_pars_vertex: Tc,
  displacementmap_vertex: bc,
  emissivemap_fragment: Ac,
  emissivemap_pars_fragment: wc,
  colorspace_fragment: Cc,
  colorspace_pars_fragment: Rc,
  envmap_fragment: Pc,
  envmap_common_pars_fragment: Uc,
  envmap_pars_fragment: Dc,
  envmap_pars_vertex: Lc,
  envmap_physical_pars_fragment: Wc,
  envmap_vertex: Fc,
  fog_vertex: Ic,
  fog_pars_vertex: Nc,
  fog_fragment: Oc,
  fog_pars_fragment: Bc,
  gradientmap_pars_fragment: kc,
  lightmap_pars_fragment: Gc,
  lights_lambert_fragment: zc,
  lights_lambert_pars_fragment: Vc,
  lights_pars_begin: Hc,
  lights_toon_fragment: Xc,
  lights_toon_pars_fragment: qc,
  lights_phong_fragment: Yc,
  lights_phong_pars_fragment: jc,
  lights_physical_fragment: Zc,
  lights_physical_pars_fragment: Kc,
  lights_fragment_begin: Jc,
  lights_fragment_maps: Qc,
  lights_fragment_end: $c,
  logdepthbuf_fragment: eu,
  logdepthbuf_pars_fragment: tu,
  logdepthbuf_pars_vertex: nu,
  logdepthbuf_vertex: iu,
  map_fragment: ru,
  map_pars_fragment: au,
  map_particle_fragment: su,
  map_particle_pars_fragment: ou,
  metalnessmap_fragment: lu,
  metalnessmap_pars_fragment: cu,
  morphinstance_vertex: uu,
  morphcolor_vertex: hu,
  morphnormal_vertex: fu,
  morphtarget_pars_vertex: du,
  morphtarget_vertex: pu,
  normal_fragment_begin: mu,
  normal_fragment_maps: gu,
  normal_pars_fragment: vu,
  normal_pars_vertex: _u,
  normal_vertex: xu,
  normalmap_pars_fragment: Su,
  clearcoat_normal_fragment_begin: yu,
  clearcoat_normal_fragment_maps: Mu,
  clearcoat_pars_fragment: Eu,
  iridescence_pars_fragment: Tu,
  opaque_fragment: bu,
  packing: Au,
  premultiplied_alpha_fragment: wu,
  project_vertex: Cu,
  dithering_fragment: Ru,
  dithering_pars_fragment: Pu,
  roughnessmap_fragment: Uu,
  roughnessmap_pars_fragment: Du,
  shadowmap_pars_fragment: Lu,
  shadowmap_pars_vertex: Fu,
  shadowmap_vertex: Iu,
  shadowmask_pars_fragment: Nu,
  skinbase_vertex: Ou,
  skinning_pars_vertex: Bu,
  skinning_vertex: ku,
  skinnormal_vertex: Gu,
  specularmap_fragment: zu,
  specularmap_pars_fragment: Vu,
  tonemapping_fragment: Hu,
  tonemapping_pars_fragment: Wu,
  transmission_fragment: Xu,
  transmission_pars_fragment: qu,
  uv_pars_fragment: Yu,
  uv_pars_vertex: ju,
  uv_vertex: Zu,
  worldpos_vertex: Ku,
  background_vert: Ju,
  background_frag: Qu,
  backgroundCube_vert: $u,
  backgroundCube_frag: eh,
  cube_vert: th,
  cube_frag: nh,
  depth_vert: ih,
  depth_frag: rh,
  distanceRGBA_vert: ah,
  distanceRGBA_frag: sh,
  equirect_vert: oh,
  equirect_frag: lh,
  linedashed_vert: ch,
  linedashed_frag: uh,
  meshbasic_vert: hh,
  meshbasic_frag: fh,
  meshlambert_vert: dh,
  meshlambert_frag: ph,
  meshmatcap_vert: mh,
  meshmatcap_frag: gh,
  meshnormal_vert: vh,
  meshnormal_frag: _h,
  meshphong_vert: xh,
  meshphong_frag: Sh,
  meshphysical_vert: yh,
  meshphysical_frag: Mh,
  meshtoon_vert: Eh,
  meshtoon_frag: Th,
  points_vert: bh,
  points_frag: Ah,
  shadow_vert: wh,
  shadow_frag: Ch,
  sprite_vert: Rh,
  sprite_frag: Ph
}, Le = {
  common: {
    diffuse: { value: /* @__PURE__ */ new Ke(16777215) },
    opacity: { value: 1 },
    map: { value: null },
    mapTransform: { value: /* @__PURE__ */ new Ye() },
    alphaMap: { value: null },
    alphaMapTransform: { value: /* @__PURE__ */ new Ye() },
    alphaTest: { value: 0 }
  },
  specularmap: {
    specularMap: { value: null },
    specularMapTransform: { value: /* @__PURE__ */ new Ye() }
  },
  envmap: {
    envMap: { value: null },
    envMapRotation: { value: /* @__PURE__ */ new Ye() },
    flipEnvMap: { value: -1 },
    reflectivity: { value: 1 },
    // basic, lambert, phong
    ior: { value: 1.5 },
    // physical
    refractionRatio: { value: 0.98 }
    // basic, lambert, phong
  },
  aomap: {
    aoMap: { value: null },
    aoMapIntensity: { value: 1 },
    aoMapTransform: { value: /* @__PURE__ */ new Ye() }
  },
  lightmap: {
    lightMap: { value: null },
    lightMapIntensity: { value: 1 },
    lightMapTransform: { value: /* @__PURE__ */ new Ye() }
  },
  bumpmap: {
    bumpMap: { value: null },
    bumpMapTransform: { value: /* @__PURE__ */ new Ye() },
    bumpScale: { value: 1 }
  },
  normalmap: {
    normalMap: { value: null },
    normalMapTransform: { value: /* @__PURE__ */ new Ye() },
    normalScale: { value: /* @__PURE__ */ new Ce(1, 1) }
  },
  displacementmap: {
    displacementMap: { value: null },
    displacementMapTransform: { value: /* @__PURE__ */ new Ye() },
    displacementScale: { value: 1 },
    displacementBias: { value: 0 }
  },
  emissivemap: {
    emissiveMap: { value: null },
    emissiveMapTransform: { value: /* @__PURE__ */ new Ye() }
  },
  metalnessmap: {
    metalnessMap: { value: null },
    metalnessMapTransform: { value: /* @__PURE__ */ new Ye() }
  },
  roughnessmap: {
    roughnessMap: { value: null },
    roughnessMapTransform: { value: /* @__PURE__ */ new Ye() }
  },
  gradientmap: {
    gradientMap: { value: null }
  },
  fog: {
    fogDensity: { value: 25e-5 },
    fogNear: { value: 1 },
    fogFar: { value: 2e3 },
    fogColor: { value: /* @__PURE__ */ new Ke(16777215) }
  },
  lights: {
    ambientLightColor: { value: [] },
    lightProbe: { value: [] },
    directionalLights: { value: [], properties: {
      direction: {},
      color: {}
    } },
    directionalLightShadows: { value: [], properties: {
      shadowIntensity: 1,
      shadowBias: {},
      shadowNormalBias: {},
      shadowRadius: {},
      shadowMapSize: {}
    } },
    directionalShadowMap: { value: [] },
    directionalShadowMatrix: { value: [] },
    spotLights: { value: [], properties: {
      color: {},
      position: {},
      direction: {},
      distance: {},
      coneCos: {},
      penumbraCos: {},
      decay: {}
    } },
    spotLightShadows: { value: [], properties: {
      shadowIntensity: 1,
      shadowBias: {},
      shadowNormalBias: {},
      shadowRadius: {},
      shadowMapSize: {}
    } },
    spotLightMap: { value: [] },
    spotShadowMap: { value: [] },
    spotLightMatrix: { value: [] },
    pointLights: { value: [], properties: {
      color: {},
      position: {},
      decay: {},
      distance: {}
    } },
    pointLightShadows: { value: [], properties: {
      shadowIntensity: 1,
      shadowBias: {},
      shadowNormalBias: {},
      shadowRadius: {},
      shadowMapSize: {},
      shadowCameraNear: {},
      shadowCameraFar: {}
    } },
    pointShadowMap: { value: [] },
    pointShadowMatrix: { value: [] },
    hemisphereLights: { value: [], properties: {
      direction: {},
      skyColor: {},
      groundColor: {}
    } },
    // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
    rectAreaLights: { value: [], properties: {
      color: {},
      position: {},
      width: {},
      height: {}
    } },
    ltc_1: { value: null },
    ltc_2: { value: null }
  },
  points: {
    diffuse: { value: /* @__PURE__ */ new Ke(16777215) },
    opacity: { value: 1 },
    size: { value: 1 },
    scale: { value: 1 },
    map: { value: null },
    alphaMap: { value: null },
    alphaMapTransform: { value: /* @__PURE__ */ new Ye() },
    alphaTest: { value: 0 },
    uvTransform: { value: /* @__PURE__ */ new Ye() }
  },
  sprite: {
    diffuse: { value: /* @__PURE__ */ new Ke(16777215) },
    opacity: { value: 1 },
    center: { value: /* @__PURE__ */ new Ce(0.5, 0.5) },
    rotation: { value: 0 },
    map: { value: null },
    mapTransform: { value: /* @__PURE__ */ new Ye() },
    alphaMap: { value: null },
    alphaMapTransform: { value: /* @__PURE__ */ new Ye() },
    alphaTest: { value: 0 }
  }
}, an = {
  basic: {
    uniforms: /* @__PURE__ */ At([
      Le.common,
      Le.specularmap,
      Le.envmap,
      Le.aomap,
      Le.lightmap,
      Le.fog
    ]),
    vertexShader: Xe.meshbasic_vert,
    fragmentShader: Xe.meshbasic_frag
  },
  lambert: {
    uniforms: /* @__PURE__ */ At([
      Le.common,
      Le.specularmap,
      Le.envmap,
      Le.aomap,
      Le.lightmap,
      Le.emissivemap,
      Le.bumpmap,
      Le.normalmap,
      Le.displacementmap,
      Le.fog,
      Le.lights,
      {
        emissive: { value: /* @__PURE__ */ new Ke(0) }
      }
    ]),
    vertexShader: Xe.meshlambert_vert,
    fragmentShader: Xe.meshlambert_frag
  },
  phong: {
    uniforms: /* @__PURE__ */ At([
      Le.common,
      Le.specularmap,
      Le.envmap,
      Le.aomap,
      Le.lightmap,
      Le.emissivemap,
      Le.bumpmap,
      Le.normalmap,
      Le.displacementmap,
      Le.fog,
      Le.lights,
      {
        emissive: { value: /* @__PURE__ */ new Ke(0) },
        specular: { value: /* @__PURE__ */ new Ke(1118481) },
        shininess: { value: 30 }
      }
    ]),
    vertexShader: Xe.meshphong_vert,
    fragmentShader: Xe.meshphong_frag
  },
  standard: {
    uniforms: /* @__PURE__ */ At([
      Le.common,
      Le.envmap,
      Le.aomap,
      Le.lightmap,
      Le.emissivemap,
      Le.bumpmap,
      Le.normalmap,
      Le.displacementmap,
      Le.roughnessmap,
      Le.metalnessmap,
      Le.fog,
      Le.lights,
      {
        emissive: { value: /* @__PURE__ */ new Ke(0) },
        roughness: { value: 1 },
        metalness: { value: 0 },
        envMapIntensity: { value: 1 }
      }
    ]),
    vertexShader: Xe.meshphysical_vert,
    fragmentShader: Xe.meshphysical_frag
  },
  toon: {
    uniforms: /* @__PURE__ */ At([
      Le.common,
      Le.aomap,
      Le.lightmap,
      Le.emissivemap,
      Le.bumpmap,
      Le.normalmap,
      Le.displacementmap,
      Le.gradientmap,
      Le.fog,
      Le.lights,
      {
        emissive: { value: /* @__PURE__ */ new Ke(0) }
      }
    ]),
    vertexShader: Xe.meshtoon_vert,
    fragmentShader: Xe.meshtoon_frag
  },
  matcap: {
    uniforms: /* @__PURE__ */ At([
      Le.common,
      Le.bumpmap,
      Le.normalmap,
      Le.displacementmap,
      Le.fog,
      {
        matcap: { value: null }
      }
    ]),
    vertexShader: Xe.meshmatcap_vert,
    fragmentShader: Xe.meshmatcap_frag
  },
  points: {
    uniforms: /* @__PURE__ */ At([
      Le.points,
      Le.fog
    ]),
    vertexShader: Xe.points_vert,
    fragmentShader: Xe.points_frag
  },
  dashed: {
    uniforms: /* @__PURE__ */ At([
      Le.common,
      Le.fog,
      {
        scale: { value: 1 },
        dashSize: { value: 1 },
        totalSize: { value: 2 }
      }
    ]),
    vertexShader: Xe.linedashed_vert,
    fragmentShader: Xe.linedashed_frag
  },
  depth: {
    uniforms: /* @__PURE__ */ At([
      Le.common,
      Le.displacementmap
    ]),
    vertexShader: Xe.depth_vert,
    fragmentShader: Xe.depth_frag
  },
  normal: {
    uniforms: /* @__PURE__ */ At([
      Le.common,
      Le.bumpmap,
      Le.normalmap,
      Le.displacementmap,
      {
        opacity: { value: 1 }
      }
    ]),
    vertexShader: Xe.meshnormal_vert,
    fragmentShader: Xe.meshnormal_frag
  },
  sprite: {
    uniforms: /* @__PURE__ */ At([
      Le.sprite,
      Le.fog
    ]),
    vertexShader: Xe.sprite_vert,
    fragmentShader: Xe.sprite_frag
  },
  background: {
    uniforms: {
      uvTransform: { value: /* @__PURE__ */ new Ye() },
      t2D: { value: null },
      backgroundIntensity: { value: 1 }
    },
    vertexShader: Xe.background_vert,
    fragmentShader: Xe.background_frag
  },
  backgroundCube: {
    uniforms: {
      envMap: { value: null },
      flipEnvMap: { value: -1 },
      backgroundBlurriness: { value: 0 },
      backgroundIntensity: { value: 1 },
      backgroundRotation: { value: /* @__PURE__ */ new Ye() }
    },
    vertexShader: Xe.backgroundCube_vert,
    fragmentShader: Xe.backgroundCube_frag
  },
  cube: {
    uniforms: {
      tCube: { value: null },
      tFlip: { value: -1 },
      opacity: { value: 1 }
    },
    vertexShader: Xe.cube_vert,
    fragmentShader: Xe.cube_frag
  },
  equirect: {
    uniforms: {
      tEquirect: { value: null }
    },
    vertexShader: Xe.equirect_vert,
    fragmentShader: Xe.equirect_frag
  },
  distanceRGBA: {
    uniforms: /* @__PURE__ */ At([
      Le.common,
      Le.displacementmap,
      {
        referencePosition: { value: /* @__PURE__ */ new j() },
        nearDistance: { value: 1 },
        farDistance: { value: 1e3 }
      }
    ]),
    vertexShader: Xe.distanceRGBA_vert,
    fragmentShader: Xe.distanceRGBA_frag
  },
  shadow: {
    uniforms: /* @__PURE__ */ At([
      Le.lights,
      Le.fog,
      {
        color: { value: /* @__PURE__ */ new Ke(0) },
        opacity: { value: 1 }
      }
    ]),
    vertexShader: Xe.shadow_vert,
    fragmentShader: Xe.shadow_frag
  }
};
an.physical = {
  uniforms: /* @__PURE__ */ At([
    an.standard.uniforms,
    {
      clearcoat: { value: 0 },
      clearcoatMap: { value: null },
      clearcoatMapTransform: { value: /* @__PURE__ */ new Ye() },
      clearcoatNormalMap: { value: null },
      clearcoatNormalMapTransform: { value: /* @__PURE__ */ new Ye() },
      clearcoatNormalScale: { value: /* @__PURE__ */ new Ce(1, 1) },
      clearcoatRoughness: { value: 0 },
      clearcoatRoughnessMap: { value: null },
      clearcoatRoughnessMapTransform: { value: /* @__PURE__ */ new Ye() },
      dispersion: { value: 0 },
      iridescence: { value: 0 },
      iridescenceMap: { value: null },
      iridescenceMapTransform: { value: /* @__PURE__ */ new Ye() },
      iridescenceIOR: { value: 1.3 },
      iridescenceThicknessMinimum: { value: 100 },
      iridescenceThicknessMaximum: { value: 400 },
      iridescenceThicknessMap: { value: null },
      iridescenceThicknessMapTransform: { value: /* @__PURE__ */ new Ye() },
      sheen: { value: 0 },
      sheenColor: { value: /* @__PURE__ */ new Ke(0) },
      sheenColorMap: { value: null },
      sheenColorMapTransform: { value: /* @__PURE__ */ new Ye() },
      sheenRoughness: { value: 1 },
      sheenRoughnessMap: { value: null },
      sheenRoughnessMapTransform: { value: /* @__PURE__ */ new Ye() },
      transmission: { value: 0 },
      transmissionMap: { value: null },
      transmissionMapTransform: { value: /* @__PURE__ */ new Ye() },
      transmissionSamplerSize: { value: /* @__PURE__ */ new Ce() },
      transmissionSamplerMap: { value: null },
      thickness: { value: 0 },
      thicknessMap: { value: null },
      thicknessMapTransform: { value: /* @__PURE__ */ new Ye() },
      attenuationDistance: { value: 0 },
      attenuationColor: { value: /* @__PURE__ */ new Ke(0) },
      specularColor: { value: /* @__PURE__ */ new Ke(1, 1, 1) },
      specularColorMap: { value: null },
      specularColorMapTransform: { value: /* @__PURE__ */ new Ye() },
      specularIntensity: { value: 1 },
      specularIntensityMap: { value: null },
      specularIntensityMapTransform: { value: /* @__PURE__ */ new Ye() },
      anisotropyVector: { value: /* @__PURE__ */ new Ce() },
      anisotropyMap: { value: null },
      anisotropyMapTransform: { value: /* @__PURE__ */ new Ye() }
    }
  ]),
  vertexShader: Xe.meshphysical_vert,
  fragmentShader: Xe.meshphysical_frag
};
const _r = { r: 0, b: 0, g: 0 }, Un = /* @__PURE__ */ new mn(), Uh = /* @__PURE__ */ new st();
function Dh(a, e, t, r, n, i, s) {
  const o = new Ke(0);
  let l = i === !0 ? 0 : 1, c, u, f = null, h = 0, d = null;
  function g(T) {
    let x = T.isScene === !0 ? T.background : null;
    return x && x.isTexture && (x = (T.backgroundBlurriness > 0 ? t : e).get(x)), x;
  }
  function v(T) {
    let x = !1;
    const _ = g(T);
    _ === null ? p(o, l) : _ && _.isColor && (p(_, 1), x = !0);
    const D = a.xr.getEnvironmentBlendMode();
    D === "additive" ? r.buffers.color.setClear(0, 0, 0, 1, s) : D === "alpha-blend" && r.buffers.color.setClear(0, 0, 0, 0, s), (a.autoClear || x) && (r.buffers.depth.setTest(!0), r.buffers.depth.setMask(!0), r.buffers.color.setMask(!0), a.clear(a.autoClearColor, a.autoClearDepth, a.autoClearStencil));
  }
  function m(T, x) {
    const _ = g(x);
    _ && (_.isCubeTexture || _.mapping === 306) ? (u === void 0 && (u = new Nt(
      new Yi(1, 1, 1),
      new bn({
        name: "BackgroundCubeMaterial",
        uniforms: di(an.backgroundCube.uniforms),
        vertexShader: an.backgroundCube.vertexShader,
        fragmentShader: an.backgroundCube.fragmentShader,
        side: 1,
        depthTest: !1,
        depthWrite: !1,
        fog: !1
      })
    ), u.geometry.deleteAttribute("normal"), u.geometry.deleteAttribute("uv"), u.onBeforeRender = function(D, C, A) {
      this.matrixWorld.copyPosition(A.matrixWorld);
    }, Object.defineProperty(u.material, "envMap", {
      get: function() {
        return this.uniforms.envMap.value;
      }
    }), n.update(u)), Un.copy(x.backgroundRotation), Un.x *= -1, Un.y *= -1, Un.z *= -1, _.isCubeTexture && _.isRenderTargetTexture === !1 && (Un.y *= -1, Un.z *= -1), u.material.uniforms.envMap.value = _, u.material.uniforms.flipEnvMap.value = _.isCubeTexture && _.isRenderTargetTexture === !1 ? -1 : 1, u.material.uniforms.backgroundBlurriness.value = x.backgroundBlurriness, u.material.uniforms.backgroundIntensity.value = x.backgroundIntensity, u.material.uniforms.backgroundRotation.value.setFromMatrix4(Uh.makeRotationFromEuler(Un)), u.material.toneMapped = $e.getTransfer(_.colorSpace) !== it, (f !== _ || h !== _.version || d !== a.toneMapping) && (u.material.needsUpdate = !0, f = _, h = _.version, d = a.toneMapping), u.layers.enableAll(), T.unshift(u, u.geometry, u.material, 0, 0, null)) : _ && _.isTexture && (c === void 0 && (c = new Nt(
      new zn(2, 2),
      new bn({
        name: "BackgroundMaterial",
        uniforms: di(an.background.uniforms),
        vertexShader: an.background.vertexShader,
        fragmentShader: an.background.fragmentShader,
        side: 0,
        depthTest: !1,
        depthWrite: !1,
        fog: !1
      })
    ), c.geometry.deleteAttribute("normal"), Object.defineProperty(c.material, "map", {
      get: function() {
        return this.uniforms.t2D.value;
      }
    }), n.update(c)), c.material.uniforms.t2D.value = _, c.material.uniforms.backgroundIntensity.value = x.backgroundIntensity, c.material.toneMapped = $e.getTransfer(_.colorSpace) !== it, _.matrixAutoUpdate === !0 && _.updateMatrix(), c.material.uniforms.uvTransform.value.copy(_.matrix), (f !== _ || h !== _.version || d !== a.toneMapping) && (c.material.needsUpdate = !0, f = _, h = _.version, d = a.toneMapping), c.layers.enableAll(), T.unshift(c, c.geometry, c.material, 0, 0, null));
  }
  function p(T, x) {
    T.getRGB(_r, Vo(a)), r.buffers.color.setClear(_r.r, _r.g, _r.b, x, s);
  }
  return {
    getClearColor: function() {
      return o;
    },
    setClearColor: function(T, x = 1) {
      o.set(T), l = x, p(o, l);
    },
    getClearAlpha: function() {
      return l;
    },
    setClearAlpha: function(T) {
      l = T, p(o, l);
    },
    render: v,
    addToRenderList: m
  };
}
function Lh(a, e) {
  const t = a.getParameter(a.MAX_VERTEX_ATTRIBS), r = {}, n = h(null);
  let i = n, s = !1;
  function o(S, F, L, B, k) {
    let O = !1;
    const z = f(B, L, F);
    i !== z && (i = z, c(i.object)), O = d(S, B, L, k), O && g(S, B, L, k), k !== null && e.update(k, a.ELEMENT_ARRAY_BUFFER), (O || s) && (s = !1, _(S, F, L, B), k !== null && a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, e.get(k).buffer));
  }
  function l() {
    return a.createVertexArray();
  }
  function c(S) {
    return a.bindVertexArray(S);
  }
  function u(S) {
    return a.deleteVertexArray(S);
  }
  function f(S, F, L) {
    const B = L.wireframe === !0;
    let k = r[S.id];
    k === void 0 && (k = {}, r[S.id] = k);
    let O = k[F.id];
    O === void 0 && (O = {}, k[F.id] = O);
    let z = O[B];
    return z === void 0 && (z = h(l()), O[B] = z), z;
  }
  function h(S) {
    const F = [], L = [], B = [];
    for (let k = 0; k < t; k++)
      F[k] = 0, L[k] = 0, B[k] = 0;
    return {
      // for backward compatibility on non-VAO support browser
      geometry: null,
      program: null,
      wireframe: !1,
      newAttributes: F,
      enabledAttributes: L,
      attributeDivisors: B,
      object: S,
      attributes: {},
      index: null
    };
  }
  function d(S, F, L, B) {
    const k = i.attributes, O = F.attributes;
    let z = 0;
    const ne = L.getAttributes();
    for (const q in ne)
      if (ne[q].location >= 0) {
        const Z = k[q];
        let N = O[q];
        if (N === void 0 && (q === "instanceMatrix" && S.instanceMatrix && (N = S.instanceMatrix), q === "instanceColor" && S.instanceColor && (N = S.instanceColor)), Z === void 0 || Z.attribute !== N || N && Z.data !== N.data) return !0;
        z++;
      }
    return i.attributesNum !== z || i.index !== B;
  }
  function g(S, F, L, B) {
    const k = {}, O = F.attributes;
    let z = 0;
    const ne = L.getAttributes();
    for (const q in ne)
      if (ne[q].location >= 0) {
        let Z = O[q];
        Z === void 0 && (q === "instanceMatrix" && S.instanceMatrix && (Z = S.instanceMatrix), q === "instanceColor" && S.instanceColor && (Z = S.instanceColor));
        const N = {};
        N.attribute = Z, Z && Z.data && (N.data = Z.data), k[q] = N, z++;
      }
    i.attributes = k, i.attributesNum = z, i.index = B;
  }
  function v() {
    const S = i.newAttributes;
    for (let F = 0, L = S.length; F < L; F++)
      S[F] = 0;
  }
  function m(S) {
    p(S, 0);
  }
  function p(S, F) {
    const L = i.newAttributes, B = i.enabledAttributes, k = i.attributeDivisors;
    L[S] = 1, B[S] === 0 && (a.enableVertexAttribArray(S), B[S] = 1), k[S] !== F && (a.vertexAttribDivisor(S, F), k[S] = F);
  }
  function T() {
    const S = i.newAttributes, F = i.enabledAttributes;
    for (let L = 0, B = F.length; L < B; L++)
      F[L] !== S[L] && (a.disableVertexAttribArray(L), F[L] = 0);
  }
  function x(S, F, L, B, k, O, z) {
    z === !0 ? a.vertexAttribIPointer(S, F, L, k, O) : a.vertexAttribPointer(S, F, L, B, k, O);
  }
  function _(S, F, L, B) {
    v();
    const k = B.attributes, O = L.getAttributes(), z = F.defaultAttributeValues;
    for (const ne in O) {
      const q = O[ne];
      if (q.location >= 0) {
        let K = k[ne];
        if (K === void 0 && (ne === "instanceMatrix" && S.instanceMatrix && (K = S.instanceMatrix), ne === "instanceColor" && S.instanceColor && (K = S.instanceColor)), K !== void 0) {
          const Z = K.normalized, N = K.itemSize, Y = e.get(K);
          if (Y === void 0) continue;
          const ie = Y.buffer, b = Y.type, U = Y.bytesPerElement, G = b === a.INT || b === a.UNSIGNED_INT || K.gpuType === 1013;
          if (K.isInterleavedBufferAttribute) {
            const I = K.data, V = I.stride, re = K.offset;
            if (I.isInstancedInterleavedBuffer) {
              for (let he = 0; he < q.locationSize; he++)
                p(q.location + he, I.meshPerAttribute);
              S.isInstancedMesh !== !0 && B._maxInstanceCount === void 0 && (B._maxInstanceCount = I.meshPerAttribute * I.count);
            } else
              for (let he = 0; he < q.locationSize; he++)
                m(q.location + he);
            a.bindBuffer(a.ARRAY_BUFFER, ie);
            for (let he = 0; he < q.locationSize; he++)
              x(
                q.location + he,
                N / q.locationSize,
                b,
                Z,
                V * U,
                (re + N / q.locationSize * he) * U,
                G
              );
          } else {
            if (K.isInstancedBufferAttribute) {
              for (let I = 0; I < q.locationSize; I++)
                p(q.location + I, K.meshPerAttribute);
              S.isInstancedMesh !== !0 && B._maxInstanceCount === void 0 && (B._maxInstanceCount = K.meshPerAttribute * K.count);
            } else
              for (let I = 0; I < q.locationSize; I++)
                m(q.location + I);
            a.bindBuffer(a.ARRAY_BUFFER, ie);
            for (let I = 0; I < q.locationSize; I++)
              x(
                q.location + I,
                N / q.locationSize,
                b,
                Z,
                N * U,
                N / q.locationSize * I * U,
                G
              );
          }
        } else if (z !== void 0) {
          const Z = z[ne];
          if (Z !== void 0)
            switch (Z.length) {
              case 2:
                a.vertexAttrib2fv(q.location, Z);
                break;
              case 3:
                a.vertexAttrib3fv(q.location, Z);
                break;
              case 4:
                a.vertexAttrib4fv(q.location, Z);
                break;
              default:
                a.vertexAttrib1fv(q.location, Z);
            }
        }
      }
    }
    T();
  }
  function D() {
    R();
    for (const S in r) {
      const F = r[S];
      for (const L in F) {
        const B = F[L];
        for (const k in B)
          u(B[k].object), delete B[k];
        delete F[L];
      }
      delete r[S];
    }
  }
  function C(S) {
    if (r[S.id] === void 0) return;
    const F = r[S.id];
    for (const L in F) {
      const B = F[L];
      for (const k in B)
        u(B[k].object), delete B[k];
      delete F[L];
    }
    delete r[S.id];
  }
  function A(S) {
    for (const F in r) {
      const L = r[F];
      if (L[S.id] === void 0) continue;
      const B = L[S.id];
      for (const k in B)
        u(B[k].object), delete B[k];
      delete L[S.id];
    }
  }
  function R() {
    E(), s = !0, i !== n && (i = n, c(i.object));
  }
  function E() {
    n.geometry = null, n.program = null, n.wireframe = !1;
  }
  return {
    setup: o,
    reset: R,
    resetDefaultState: E,
    dispose: D,
    releaseStatesOfGeometry: C,
    releaseStatesOfProgram: A,
    initAttributes: v,
    enableAttribute: m,
    disableUnusedAttributes: T
  };
}
function Fh(a, e, t) {
  let r;
  function n(c) {
    r = c;
  }
  function i(c, u) {
    a.drawArrays(r, c, u), t.update(u, r, 1);
  }
  function s(c, u, f) {
    f !== 0 && (a.drawArraysInstanced(r, c, u, f), t.update(u, r, f));
  }
  function o(c, u, f) {
    if (f === 0) return;
    e.get("WEBGL_multi_draw").multiDrawArraysWEBGL(r, c, 0, u, 0, f);
    let d = 0;
    for (let g = 0; g < f; g++)
      d += u[g];
    t.update(d, r, 1);
  }
  function l(c, u, f, h) {
    if (f === 0) return;
    const d = e.get("WEBGL_multi_draw");
    if (d === null)
      for (let g = 0; g < c.length; g++)
        s(c[g], u[g], h[g]);
    else {
      d.multiDrawArraysInstancedWEBGL(r, c, 0, u, 0, h, 0, f);
      let g = 0;
      for (let v = 0; v < f; v++)
        g += u[v] * h[v];
      t.update(g, r, 1);
    }
  }
  this.setMode = n, this.render = i, this.renderInstances = s, this.renderMultiDraw = o, this.renderMultiDrawInstances = l;
}
function Ih(a, e, t, r) {
  let n;
  function i() {
    if (n !== void 0) return n;
    if (e.has("EXT_texture_filter_anisotropic") === !0) {
      const A = e.get("EXT_texture_filter_anisotropic");
      n = a.getParameter(A.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
    } else
      n = 0;
    return n;
  }
  function s(A) {
    return !(A !== 1023 && r.convert(A) !== a.getParameter(a.IMPLEMENTATION_COLOR_READ_FORMAT));
  }
  function o(A) {
    const R = A === 1016 && (e.has("EXT_color_buffer_half_float") || e.has("EXT_color_buffer_float"));
    return !(A !== 1009 && r.convert(A) !== a.getParameter(a.IMPLEMENTATION_COLOR_READ_TYPE) && // Edge and Chrome Mac < 52 (#9513)
    A !== 1015 && !R);
  }
  function l(A) {
    if (A === "highp") {
      if (a.getShaderPrecisionFormat(a.VERTEX_SHADER, a.HIGH_FLOAT).precision > 0 && a.getShaderPrecisionFormat(a.FRAGMENT_SHADER, a.HIGH_FLOAT).precision > 0)
        return "highp";
      A = "mediump";
    }
    return A === "mediump" && a.getShaderPrecisionFormat(a.VERTEX_SHADER, a.MEDIUM_FLOAT).precision > 0 && a.getShaderPrecisionFormat(a.FRAGMENT_SHADER, a.MEDIUM_FLOAT).precision > 0 ? "mediump" : "lowp";
  }
  let c = t.precision !== void 0 ? t.precision : "highp";
  const u = l(c);
  u !== c && (console.warn("THREE.WebGLRenderer:", c, "not supported, using", u, "instead."), c = u);
  const f = t.logarithmicDepthBuffer === !0, h = t.reverseDepthBuffer === !0 && e.has("EXT_clip_control"), d = a.getParameter(a.MAX_TEXTURE_IMAGE_UNITS), g = a.getParameter(a.MAX_VERTEX_TEXTURE_IMAGE_UNITS), v = a.getParameter(a.MAX_TEXTURE_SIZE), m = a.getParameter(a.MAX_CUBE_MAP_TEXTURE_SIZE), p = a.getParameter(a.MAX_VERTEX_ATTRIBS), T = a.getParameter(a.MAX_VERTEX_UNIFORM_VECTORS), x = a.getParameter(a.MAX_VARYING_VECTORS), _ = a.getParameter(a.MAX_FRAGMENT_UNIFORM_VECTORS), D = g > 0, C = a.getParameter(a.MAX_SAMPLES);
  return {
    isWebGL2: !0,
    // keeping this for backwards compatibility
    getMaxAnisotropy: i,
    getMaxPrecision: l,
    textureFormatReadable: s,
    textureTypeReadable: o,
    precision: c,
    logarithmicDepthBuffer: f,
    reverseDepthBuffer: h,
    maxTextures: d,
    maxVertexTextures: g,
    maxTextureSize: v,
    maxCubemapSize: m,
    maxAttributes: p,
    maxVertexUniforms: T,
    maxVaryings: x,
    maxFragmentUniforms: _,
    vertexTextures: D,
    maxSamples: C
  };
}
function Nh(a) {
  const e = this;
  let t = null, r = 0, n = !1, i = !1;
  const s = new Fn(), o = new Ye(), l = { value: null, needsUpdate: !1 };
  this.uniform = l, this.numPlanes = 0, this.numIntersection = 0, this.init = function(f, h) {
    const d = f.length !== 0 || h || // enable state of previous frame - the clipping code has to
    // run another frame in order to reset the state:
    r !== 0 || n;
    return n = h, r = f.length, d;
  }, this.beginShadows = function() {
    i = !0, u(null);
  }, this.endShadows = function() {
    i = !1;
  }, this.setGlobalState = function(f, h) {
    t = u(f, h, 0);
  }, this.setState = function(f, h, d) {
    const g = f.clippingPlanes, v = f.clipIntersection, m = f.clipShadows, p = a.get(f);
    if (!n || g === null || g.length === 0 || i && !m)
      i ? u(null) : c();
    else {
      const T = i ? 0 : r, x = T * 4;
      let _ = p.clippingState || null;
      l.value = _, _ = u(g, h, x, d);
      for (let D = 0; D !== x; ++D)
        _[D] = t[D];
      p.clippingState = _, this.numIntersection = v ? this.numPlanes : 0, this.numPlanes += T;
    }
  };
  function c() {
    l.value !== t && (l.value = t, l.needsUpdate = r > 0), e.numPlanes = r, e.numIntersection = 0;
  }
  function u(f, h, d, g) {
    const v = f !== null ? f.length : 0;
    let m = null;
    if (v !== 0) {
      if (m = l.value, g !== !0 || m === null) {
        const p = d + v * 4, T = h.matrixWorldInverse;
        o.getNormalMatrix(T), (m === null || m.length < p) && (m = new Float32Array(p));
        for (let x = 0, _ = d; x !== v; ++x, _ += 4)
          s.copy(f[x]).applyMatrix4(T, o), s.normal.toArray(m, _), m[_ + 3] = s.constant;
      }
      l.value = m, l.needsUpdate = !0;
    }
    return e.numPlanes = v, e.numIntersection = 0, m;
  }
}
function Oh(a) {
  let e = /* @__PURE__ */ new WeakMap();
  function t(s, o) {
    return o === 303 ? s.mapping = 301 : o === 304 && (s.mapping = 302), s;
  }
  function r(s) {
    if (s && s.isTexture) {
      const o = s.mapping;
      if (o === 303 || o === 304)
        if (e.has(s)) {
          const l = e.get(s).texture;
          return t(l, s.mapping);
        } else {
          const l = s.image;
          if (l && l.height > 0) {
            const c = new jl(l.height);
            return c.fromEquirectangularTexture(a, s), e.set(s, c), s.addEventListener("dispose", n), t(c.texture, s.mapping);
          } else
            return null;
        }
    }
    return s;
  }
  function n(s) {
    const o = s.target;
    o.removeEventListener("dispose", n);
    const l = e.get(o);
    l !== void 0 && (e.delete(o), l.dispose());
  }
  function i() {
    e = /* @__PURE__ */ new WeakMap();
  }
  return {
    get: r,
    dispose: i
  };
}
class Yo extends Ho {
  constructor(e = -1, t = 1, r = 1, n = -1, i = 0.1, s = 2e3) {
    super(), this.isOrthographicCamera = !0, this.type = "OrthographicCamera", this.zoom = 1, this.view = null, this.left = e, this.right = t, this.top = r, this.bottom = n, this.near = i, this.far = s, this.updateProjectionMatrix();
  }
  copy(e, t) {
    return super.copy(e, t), this.left = e.left, this.right = e.right, this.top = e.top, this.bottom = e.bottom, this.near = e.near, this.far = e.far, this.zoom = e.zoom, this.view = e.view === null ? null : Object.assign({}, e.view), this;
  }
  setViewOffset(e, t, r, n, i, s) {
    this.view === null && (this.view = {
      enabled: !0,
      fullWidth: 1,
      fullHeight: 1,
      offsetX: 0,
      offsetY: 0,
      width: 1,
      height: 1
    }), this.view.enabled = !0, this.view.fullWidth = e, this.view.fullHeight = t, this.view.offsetX = r, this.view.offsetY = n, this.view.width = i, this.view.height = s, this.updateProjectionMatrix();
  }
  clearViewOffset() {
    this.view !== null && (this.view.enabled = !1), this.updateProjectionMatrix();
  }
  updateProjectionMatrix() {
    const e = (this.right - this.left) / (2 * this.zoom), t = (this.top - this.bottom) / (2 * this.zoom), r = (this.right + this.left) / 2, n = (this.top + this.bottom) / 2;
    let i = r - e, s = r + e, o = n + t, l = n - t;
    if (this.view !== null && this.view.enabled) {
      const c = (this.right - this.left) / this.view.fullWidth / this.zoom, u = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
      i += c * this.view.offsetX, s = i + c * this.view.width, o -= u * this.view.offsetY, l = o - u * this.view.height;
    }
    this.projectionMatrix.makeOrthographic(i, s, o, l, this.near, this.far, this.coordinateSystem), this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  }
  toJSON(e) {
    const t = super.toJSON(e);
    return t.object.zoom = this.zoom, t.object.left = this.left, t.object.right = this.right, t.object.top = this.top, t.object.bottom = this.bottom, t.object.near = this.near, t.object.far = this.far, this.view !== null && (t.object.view = Object.assign({}, this.view)), t;
  }
}
const oi = 4, ks = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582], Nn = 20, Ta = /* @__PURE__ */ new Yo(), Gs = /* @__PURE__ */ new Ke();
let ba = null, Aa = 0, wa = 0, Ca = !1;
const In = (1 + Math.sqrt(5)) / 2, ri = 1 / In, zs = [
  /* @__PURE__ */ new j(-In, ri, 0),
  /* @__PURE__ */ new j(In, ri, 0),
  /* @__PURE__ */ new j(-ri, 0, In),
  /* @__PURE__ */ new j(ri, 0, In),
  /* @__PURE__ */ new j(0, In, -ri),
  /* @__PURE__ */ new j(0, In, ri),
  /* @__PURE__ */ new j(-1, 1, -1),
  /* @__PURE__ */ new j(1, 1, -1),
  /* @__PURE__ */ new j(-1, 1, 1),
  /* @__PURE__ */ new j(1, 1, 1)
];
class Vs {
  constructor(e) {
    this._renderer = e, this._pingPongRenderTarget = null, this._lodMax = 0, this._cubeSize = 0, this._lodPlanes = [], this._sizeLods = [], this._sigmas = [], this._blurMaterial = null, this._cubemapMaterial = null, this._equirectMaterial = null, this._compileMaterial(this._blurMaterial);
  }
  /**
   * Generates a PMREM from a supplied Scene, which can be faster than using an
   * image if networking bandwidth is low. Optional sigma specifies a blur radius
   * in radians to be applied to the scene before PMREM generation. Optional near
   * and far planes ensure the scene is rendered in its entirety (the cubeCamera
   * is placed at the origin).
   */
  fromScene(e, t = 0, r = 0.1, n = 100) {
    ba = this._renderer.getRenderTarget(), Aa = this._renderer.getActiveCubeFace(), wa = this._renderer.getActiveMipmapLevel(), Ca = this._renderer.xr.enabled, this._renderer.xr.enabled = !1, this._setSize(256);
    const i = this._allocateTargets();
    return i.depthBuffer = !0, this._sceneToCubeUV(e, r, n, i), t > 0 && this._blur(i, 0, 0, t), this._applyPMREM(i), this._cleanup(i), i;
  }
  /**
   * Generates a PMREM from an equirectangular texture, which can be either LDR
   * or HDR. The ideal input image size is 1k (1024 x 512),
   * as this matches best with the 256 x 256 cubemap output.
   * The smallest supported equirectangular image size is 64 x 32.
   */
  fromEquirectangular(e, t = null) {
    return this._fromTexture(e, t);
  }
  /**
   * Generates a PMREM from an cubemap texture, which can be either LDR
   * or HDR. The ideal input cube size is 256 x 256,
   * as this matches best with the 256 x 256 cubemap output.
   * The smallest supported cube size is 16 x 16.
   */
  fromCubemap(e, t = null) {
    return this._fromTexture(e, t);
  }
  /**
   * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
   * your texture's network fetch for increased concurrency.
   */
  compileCubemapShader() {
    this._cubemapMaterial === null && (this._cubemapMaterial = Xs(), this._compileMaterial(this._cubemapMaterial));
  }
  /**
   * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
   * your texture's network fetch for increased concurrency.
   */
  compileEquirectangularShader() {
    this._equirectMaterial === null && (this._equirectMaterial = Ws(), this._compileMaterial(this._equirectMaterial));
  }
  /**
   * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
   * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
   * one of them will cause any others to also become unusable.
   */
  dispose() {
    this._dispose(), this._cubemapMaterial !== null && this._cubemapMaterial.dispose(), this._equirectMaterial !== null && this._equirectMaterial.dispose();
  }
  // private interface
  _setSize(e) {
    this._lodMax = Math.floor(Math.log2(e)), this._cubeSize = Math.pow(2, this._lodMax);
  }
  _dispose() {
    this._blurMaterial !== null && this._blurMaterial.dispose(), this._pingPongRenderTarget !== null && this._pingPongRenderTarget.dispose();
    for (let e = 0; e < this._lodPlanes.length; e++)
      this._lodPlanes[e].dispose();
  }
  _cleanup(e) {
    this._renderer.setRenderTarget(ba, Aa, wa), this._renderer.xr.enabled = Ca, e.scissorTest = !1, xr(e, 0, 0, e.width, e.height);
  }
  _fromTexture(e, t) {
    e.mapping === 301 || e.mapping === 302 ? this._setSize(e.image.length === 0 ? 16 : e.image[0].width || e.image[0].image.width) : this._setSize(e.image.width / 4), ba = this._renderer.getRenderTarget(), Aa = this._renderer.getActiveCubeFace(), wa = this._renderer.getActiveMipmapLevel(), Ca = this._renderer.xr.enabled, this._renderer.xr.enabled = !1;
    const r = t || this._allocateTargets();
    return this._textureToCubeUV(e, r), this._applyPMREM(r), this._cleanup(r), r;
  }
  _allocateTargets() {
    const e = 3 * Math.max(this._cubeSize, 112), t = 4 * this._cubeSize, r = {
      magFilter: 1006,
      minFilter: 1006,
      generateMipmaps: !1,
      type: 1016,
      format: 1023,
      colorSpace: pi,
      depthBuffer: !1
    }, n = Hs(e, t, r);
    if (this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== e || this._pingPongRenderTarget.height !== t) {
      this._pingPongRenderTarget !== null && this._dispose(), this._pingPongRenderTarget = Hs(e, t, r);
      const { _lodMax: i } = this;
      ({ sizeLods: this._sizeLods, lodPlanes: this._lodPlanes, sigmas: this._sigmas } = Bh(i)), this._blurMaterial = kh(i, e, t);
    }
    return n;
  }
  _compileMaterial(e) {
    const t = new Nt(this._lodPlanes[0], e);
    this._renderer.compile(t, Ta);
  }
  _sceneToCubeUV(e, t, r, n) {
    const o = new Qt(90, 1, t, r), l = [1, -1, 1, 1, 1, 1], c = [1, 1, 1, -1, -1, -1], u = this._renderer, f = u.autoClear, h = u.toneMapping;
    u.getClearColor(Gs), u.toneMapping = 0, u.autoClear = !1;
    const d = new Vi({
      name: "PMREM.Background",
      side: 1,
      depthWrite: !1,
      depthTest: !1
    }), g = new Nt(new Yi(), d);
    let v = !1;
    const m = e.background;
    m ? m.isColor && (d.color.copy(m), e.background = null, v = !0) : (d.color.copy(Gs), v = !0);
    for (let p = 0; p < 6; p++) {
      const T = p % 3;
      T === 0 ? (o.up.set(0, l[p], 0), o.lookAt(c[p], 0, 0)) : T === 1 ? (o.up.set(0, 0, l[p]), o.lookAt(0, c[p], 0)) : (o.up.set(0, l[p], 0), o.lookAt(0, 0, c[p]));
      const x = this._cubeSize;
      xr(n, T * x, p > 2 ? x : 0, x, x), u.setRenderTarget(n), v && u.render(g, o), u.render(e, o);
    }
    g.geometry.dispose(), g.material.dispose(), u.toneMapping = h, u.autoClear = f, e.background = m;
  }
  _textureToCubeUV(e, t) {
    const r = this._renderer, n = e.mapping === 301 || e.mapping === 302;
    n ? (this._cubemapMaterial === null && (this._cubemapMaterial = Xs()), this._cubemapMaterial.uniforms.flipEnvMap.value = e.isRenderTargetTexture === !1 ? -1 : 1) : this._equirectMaterial === null && (this._equirectMaterial = Ws());
    const i = n ? this._cubemapMaterial : this._equirectMaterial, s = new Nt(this._lodPlanes[0], i), o = i.uniforms;
    o.envMap.value = e;
    const l = this._cubeSize;
    xr(t, 0, 0, 3 * l, 2 * l), r.setRenderTarget(t), r.render(s, Ta);
  }
  _applyPMREM(e) {
    const t = this._renderer, r = t.autoClear;
    t.autoClear = !1;
    const n = this._lodPlanes.length;
    for (let i = 1; i < n; i++) {
      const s = Math.sqrt(this._sigmas[i] * this._sigmas[i] - this._sigmas[i - 1] * this._sigmas[i - 1]), o = zs[(n - i - 1) % zs.length];
      this._blur(e, i - 1, i, s, o);
    }
    t.autoClear = r;
  }
  /**
   * This is a two-pass Gaussian blur for a cubemap. Normally this is done
   * vertically and horizontally, but this breaks down on a cube. Here we apply
   * the blur latitudinally (around the poles), and then longitudinally (towards
   * the poles) to approximate the orthogonally-separable blur. It is least
   * accurate at the poles, but still does a decent job.
   */
  _blur(e, t, r, n, i) {
    const s = this._pingPongRenderTarget;
    this._halfBlur(
      e,
      s,
      t,
      r,
      n,
      "latitudinal",
      i
    ), this._halfBlur(
      s,
      e,
      r,
      r,
      n,
      "longitudinal",
      i
    );
  }
  _halfBlur(e, t, r, n, i, s, o) {
    const l = this._renderer, c = this._blurMaterial;
    s !== "latitudinal" && s !== "longitudinal" && console.error(
      "blur direction must be either latitudinal or longitudinal!"
    );
    const u = 3, f = new Nt(this._lodPlanes[n], c), h = c.uniforms, d = this._sizeLods[r] - 1, g = isFinite(i) ? Math.PI / (2 * d) : 2 * Math.PI / (2 * Nn - 1), v = i / g, m = isFinite(i) ? 1 + Math.floor(u * v) : Nn;
    m > Nn && console.warn(`sigmaRadians, ${i}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${Nn}`);
    const p = [];
    let T = 0;
    for (let A = 0; A < Nn; ++A) {
      const R = A / v, E = Math.exp(-R * R / 2);
      p.push(E), A === 0 ? T += E : A < m && (T += 2 * E);
    }
    for (let A = 0; A < p.length; A++)
      p[A] = p[A] / T;
    h.envMap.value = e.texture, h.samples.value = m, h.weights.value = p, h.latitudinal.value = s === "latitudinal", o && (h.poleAxis.value = o);
    const { _lodMax: x } = this;
    h.dTheta.value = g, h.mipInt.value = x - r;
    const _ = this._sizeLods[n], D = 3 * _ * (n > x - oi ? n - x + oi : 0), C = 4 * (this._cubeSize - _);
    xr(t, D, C, 3 * _, 2 * _), l.setRenderTarget(t), l.render(f, Ta);
  }
}
function Bh(a) {
  const e = [], t = [], r = [];
  let n = a;
  const i = a - oi + 1 + ks.length;
  for (let s = 0; s < i; s++) {
    const o = Math.pow(2, n);
    t.push(o);
    let l = 1 / o;
    s > a - oi ? l = ks[s - a + oi - 1] : s === 0 && (l = 0), r.push(l);
    const c = 1 / (o - 2), u = -c, f = 1 + c, h = [u, u, f, u, f, f, u, u, f, f, u, f], d = 6, g = 6, v = 3, m = 2, p = 1, T = new Float32Array(v * g * d), x = new Float32Array(m * g * d), _ = new Float32Array(p * g * d);
    for (let C = 0; C < d; C++) {
      const A = C % 3 * 2 / 3 - 1, R = C > 2 ? 0 : -1, E = [
        A,
        R,
        0,
        A + 2 / 3,
        R,
        0,
        A + 2 / 3,
        R + 1,
        0,
        A,
        R,
        0,
        A + 2 / 3,
        R + 1,
        0,
        A,
        R + 1,
        0
      ];
      T.set(E, v * g * C), x.set(h, m * g * C);
      const S = [C, C, C, C, C, C];
      _.set(S, p * g * C);
    }
    const D = new St();
    D.setAttribute("position", new en(T, v)), D.setAttribute("uv", new en(x, m)), D.setAttribute("faceIndex", new en(_, p)), e.push(D), n > oi && n--;
  }
  return { lodPlanes: e, sizeLods: t, sigmas: r };
}
function Hs(a, e, t) {
  const r = new Bn(a, e, t);
  return r.texture.mapping = 306, r.texture.name = "PMREM.cubeUv", r.scissorTest = !0, r;
}
function xr(a, e, t, r, n) {
  a.viewport.set(e, t, r, n), a.scissor.set(e, t, r, n);
}
function kh(a, e, t) {
  const r = new Float32Array(Nn), n = new j(0, 1, 0);
  return new bn({
    name: "SphericalGaussianBlur",
    defines: {
      n: Nn,
      CUBEUV_TEXEL_WIDTH: 1 / e,
      CUBEUV_TEXEL_HEIGHT: 1 / t,
      CUBEUV_MAX_MIP: `${a}.0`
    },
    uniforms: {
      envMap: { value: null },
      samples: { value: 1 },
      weights: { value: r },
      latitudinal: { value: !1 },
      dTheta: { value: 0 },
      mipInt: { value: 0 },
      poleAxis: { value: n }
    },
    vertexShader: $a(),
    fragmentShader: (
      /* glsl */
      `

			precision mediump float;
			precision mediump int;

			varying vec3 vOutputDirection;

			uniform sampler2D envMap;
			uniform int samples;
			uniform float weights[ n ];
			uniform bool latitudinal;
			uniform float dTheta;
			uniform float mipInt;
			uniform vec3 poleAxis;

			#define ENVMAP_TYPE_CUBE_UV
			#include <cube_uv_reflection_fragment>

			vec3 getSample( float theta, vec3 axis ) {

				float cosTheta = cos( theta );
				// Rodrigues' axis-angle rotation
				vec3 sampleDirection = vOutputDirection * cosTheta
					+ cross( axis, vOutputDirection ) * sin( theta )
					+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );

				return bilinearCubeUV( envMap, sampleDirection, mipInt );

			}

			void main() {

				vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );

				if ( all( equal( axis, vec3( 0.0 ) ) ) ) {

					axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );

				}

				axis = normalize( axis );

				gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
				gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );

				for ( int i = 1; i < n; i++ ) {

					if ( i >= samples ) {

						break;

					}

					float theta = dTheta * float( i );
					gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
					gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );

				}

			}
		`
    ),
    blending: 0,
    depthTest: !1,
    depthWrite: !1
  });
}
function Ws() {
  return new bn({
    name: "EquirectangularToCubeUV",
    uniforms: {
      envMap: { value: null }
    },
    vertexShader: $a(),
    fragmentShader: (
      /* glsl */
      `

			precision mediump float;
			precision mediump int;

			varying vec3 vOutputDirection;

			uniform sampler2D envMap;

			#include <common>

			void main() {

				vec3 outputDirection = normalize( vOutputDirection );
				vec2 uv = equirectUv( outputDirection );

				gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );

			}
		`
    ),
    blending: 0,
    depthTest: !1,
    depthWrite: !1
  });
}
function Xs() {
  return new bn({
    name: "CubemapToCubeUV",
    uniforms: {
      envMap: { value: null },
      flipEnvMap: { value: -1 }
    },
    vertexShader: $a(),
    fragmentShader: (
      /* glsl */
      `

			precision mediump float;
			precision mediump int;

			uniform float flipEnvMap;

			varying vec3 vOutputDirection;

			uniform samplerCube envMap;

			void main() {

				gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );

			}
		`
    ),
    blending: 0,
    depthTest: !1,
    depthWrite: !1
  });
}
function $a() {
  return (
    /* glsl */
    `

		precision mediump float;
		precision mediump int;

		attribute float faceIndex;

		varying vec3 vOutputDirection;

		// RH coordinate system; PMREM face-indexing convention
		vec3 getDirection( vec2 uv, float face ) {

			uv = 2.0 * uv - 1.0;

			vec3 direction = vec3( uv, 1.0 );

			if ( face == 0.0 ) {

				direction = direction.zyx; // ( 1, v, u ) pos x

			} else if ( face == 1.0 ) {

				direction = direction.xzy;
				direction.xz *= -1.0; // ( -u, 1, -v ) pos y

			} else if ( face == 2.0 ) {

				direction.x *= -1.0; // ( -u, v, 1 ) pos z

			} else if ( face == 3.0 ) {

				direction = direction.zyx;
				direction.xz *= -1.0; // ( -1, v, -u ) neg x

			} else if ( face == 4.0 ) {

				direction = direction.xzy;
				direction.xy *= -1.0; // ( -u, -1, v ) neg y

			} else if ( face == 5.0 ) {

				direction.z *= -1.0; // ( u, v, -1 ) neg z

			}

			return direction;

		}

		void main() {

			vOutputDirection = getDirection( uv, faceIndex );
			gl_Position = vec4( position, 1.0 );

		}
	`
  );
}
function Gh(a) {
  let e = /* @__PURE__ */ new WeakMap(), t = null;
  function r(o) {
    if (o && o.isTexture) {
      const l = o.mapping, c = l === 303 || l === 304, u = l === 301 || l === 302;
      if (c || u) {
        let f = e.get(o);
        const h = f !== void 0 ? f.texture.pmremVersion : 0;
        if (o.isRenderTargetTexture && o.pmremVersion !== h)
          return t === null && (t = new Vs(a)), f = c ? t.fromEquirectangular(o, f) : t.fromCubemap(o, f), f.texture.pmremVersion = o.pmremVersion, e.set(o, f), f.texture;
        if (f !== void 0)
          return f.texture;
        {
          const d = o.image;
          return c && d && d.height > 0 || u && d && n(d) ? (t === null && (t = new Vs(a)), f = c ? t.fromEquirectangular(o) : t.fromCubemap(o), f.texture.pmremVersion = o.pmremVersion, e.set(o, f), o.addEventListener("dispose", i), f.texture) : null;
        }
      }
    }
    return o;
  }
  function n(o) {
    let l = 0;
    const c = 6;
    for (let u = 0; u < c; u++)
      o[u] !== void 0 && l++;
    return l === c;
  }
  function i(o) {
    const l = o.target;
    l.removeEventListener("dispose", i);
    const c = e.get(l);
    c !== void 0 && (e.delete(l), c.dispose());
  }
  function s() {
    e = /* @__PURE__ */ new WeakMap(), t !== null && (t.dispose(), t = null);
  }
  return {
    get: r,
    dispose: s
  };
}
function zh(a) {
  const e = {};
  function t(r) {
    if (e[r] !== void 0)
      return e[r];
    let n;
    switch (r) {
      case "WEBGL_depth_texture":
        n = a.getExtension("WEBGL_depth_texture") || a.getExtension("MOZ_WEBGL_depth_texture") || a.getExtension("WEBKIT_WEBGL_depth_texture");
        break;
      case "EXT_texture_filter_anisotropic":
        n = a.getExtension("EXT_texture_filter_anisotropic") || a.getExtension("MOZ_EXT_texture_filter_anisotropic") || a.getExtension("WEBKIT_EXT_texture_filter_anisotropic");
        break;
      case "WEBGL_compressed_texture_s3tc":
        n = a.getExtension("WEBGL_compressed_texture_s3tc") || a.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || a.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");
        break;
      case "WEBGL_compressed_texture_pvrtc":
        n = a.getExtension("WEBGL_compressed_texture_pvrtc") || a.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");
        break;
      default:
        n = a.getExtension(r);
    }
    return e[r] = n, n;
  }
  return {
    has: function(r) {
      return t(r) !== null;
    },
    init: function() {
      t("EXT_color_buffer_float"), t("WEBGL_clip_cull_distance"), t("OES_texture_float_linear"), t("EXT_color_buffer_half_float"), t("WEBGL_multisampled_render_to_texture"), t("WEBGL_render_shared_exponent");
    },
    get: function(r) {
      const n = t(r);
      return n === null && Ni("THREE.WebGLRenderer: " + r + " extension not supported."), n;
    }
  };
}
function Vh(a, e, t, r) {
  const n = {}, i = /* @__PURE__ */ new WeakMap();
  function s(f) {
    const h = f.target;
    h.index !== null && e.remove(h.index);
    for (const g in h.attributes)
      e.remove(h.attributes[g]);
    for (const g in h.morphAttributes) {
      const v = h.morphAttributes[g];
      for (let m = 0, p = v.length; m < p; m++)
        e.remove(v[m]);
    }
    h.removeEventListener("dispose", s), delete n[h.id];
    const d = i.get(h);
    d && (e.remove(d), i.delete(h)), r.releaseStatesOfGeometry(h), h.isInstancedBufferGeometry === !0 && delete h._maxInstanceCount, t.memory.geometries--;
  }
  function o(f, h) {
    return n[h.id] === !0 || (h.addEventListener("dispose", s), n[h.id] = !0, t.memory.geometries++), h;
  }
  function l(f) {
    const h = f.attributes;
    for (const g in h)
      e.update(h[g], a.ARRAY_BUFFER);
    const d = f.morphAttributes;
    for (const g in d) {
      const v = d[g];
      for (let m = 0, p = v.length; m < p; m++)
        e.update(v[m], a.ARRAY_BUFFER);
    }
  }
  function c(f) {
    const h = [], d = f.index, g = f.attributes.position;
    let v = 0;
    if (d !== null) {
      const T = d.array;
      v = d.version;
      for (let x = 0, _ = T.length; x < _; x += 3) {
        const D = T[x + 0], C = T[x + 1], A = T[x + 2];
        h.push(D, C, C, A, A, D);
      }
    } else if (g !== void 0) {
      const T = g.array;
      v = g.version;
      for (let x = 0, _ = T.length / 3 - 1; x < _; x += 3) {
        const D = x + 0, C = x + 1, A = x + 2;
        h.push(D, C, C, A, A, D);
      }
    } else
      return;
    const m = new (Io(h) ? zo : Go)(h, 1);
    m.version = v;
    const p = i.get(f);
    p && e.remove(p), i.set(f, m);
  }
  function u(f) {
    const h = i.get(f);
    if (h) {
      const d = f.index;
      d !== null && h.version < d.version && c(f);
    } else
      c(f);
    return i.get(f);
  }
  return {
    get: o,
    update: l,
    getWireframeAttribute: u
  };
}
function Hh(a, e, t) {
  let r;
  function n(h) {
    r = h;
  }
  let i, s;
  function o(h) {
    i = h.type, s = h.bytesPerElement;
  }
  function l(h, d) {
    a.drawElements(r, d, i, h * s), t.update(d, r, 1);
  }
  function c(h, d, g) {
    g !== 0 && (a.drawElementsInstanced(r, d, i, h * s, g), t.update(d, r, g));
  }
  function u(h, d, g) {
    if (g === 0) return;
    e.get("WEBGL_multi_draw").multiDrawElementsWEBGL(r, d, 0, i, h, 0, g);
    let m = 0;
    for (let p = 0; p < g; p++)
      m += d[p];
    t.update(m, r, 1);
  }
  function f(h, d, g, v) {
    if (g === 0) return;
    const m = e.get("WEBGL_multi_draw");
    if (m === null)
      for (let p = 0; p < h.length; p++)
        c(h[p] / s, d[p], v[p]);
    else {
      m.multiDrawElementsInstancedWEBGL(r, d, 0, i, h, 0, v, 0, g);
      let p = 0;
      for (let T = 0; T < g; T++)
        p += d[T] * v[T];
      t.update(p, r, 1);
    }
  }
  this.setMode = n, this.setIndex = o, this.render = l, this.renderInstances = c, this.renderMultiDraw = u, this.renderMultiDrawInstances = f;
}
function Wh(a) {
  const e = {
    geometries: 0,
    textures: 0
  }, t = {
    frame: 0,
    calls: 0,
    triangles: 0,
    points: 0,
    lines: 0
  };
  function r(i, s, o) {
    switch (t.calls++, s) {
      case a.TRIANGLES:
        t.triangles += o * (i / 3);
        break;
      case a.LINES:
        t.lines += o * (i / 2);
        break;
      case a.LINE_STRIP:
        t.lines += o * (i - 1);
        break;
      case a.LINE_LOOP:
        t.lines += o * i;
        break;
      case a.POINTS:
        t.points += o * i;
        break;
      default:
        console.error("THREE.WebGLInfo: Unknown draw mode:", s);
        break;
    }
  }
  function n() {
    t.calls = 0, t.triangles = 0, t.points = 0, t.lines = 0;
  }
  return {
    memory: e,
    render: t,
    programs: null,
    autoReset: !0,
    reset: n,
    update: r
  };
}
function Xh(a, e, t) {
  const r = /* @__PURE__ */ new WeakMap(), n = new ot();
  function i(s, o, l) {
    const c = s.morphTargetInfluences, u = o.morphAttributes.position || o.morphAttributes.normal || o.morphAttributes.color, f = u !== void 0 ? u.length : 0;
    let h = r.get(o);
    if (h === void 0 || h.count !== f) {
      let E = function() {
        A.dispose(), r.delete(o), o.removeEventListener("dispose", E);
      };
      h !== void 0 && h.texture.dispose();
      const d = o.morphAttributes.position !== void 0, g = o.morphAttributes.normal !== void 0, v = o.morphAttributes.color !== void 0, m = o.morphAttributes.position || [], p = o.morphAttributes.normal || [], T = o.morphAttributes.color || [];
      let x = 0;
      d === !0 && (x = 1), g === !0 && (x = 2), v === !0 && (x = 3);
      let _ = o.attributes.position.count * x, D = 1;
      _ > e.maxTextureSize && (D = Math.ceil(_ / e.maxTextureSize), _ = e.maxTextureSize);
      const C = new Float32Array(_ * D * 4 * f), A = new Oo(C, _, D, f);
      A.type = 1015, A.needsUpdate = !0;
      const R = x * 4;
      for (let S = 0; S < f; S++) {
        const F = m[S], L = p[S], B = T[S], k = _ * D * 4 * S;
        for (let O = 0; O < F.count; O++) {
          const z = O * R;
          d === !0 && (n.fromBufferAttribute(F, O), C[k + z + 0] = n.x, C[k + z + 1] = n.y, C[k + z + 2] = n.z, C[k + z + 3] = 0), g === !0 && (n.fromBufferAttribute(L, O), C[k + z + 4] = n.x, C[k + z + 5] = n.y, C[k + z + 6] = n.z, C[k + z + 7] = 0), v === !0 && (n.fromBufferAttribute(B, O), C[k + z + 8] = n.x, C[k + z + 9] = n.y, C[k + z + 10] = n.z, C[k + z + 11] = B.itemSize === 4 ? n.w : 1);
        }
      }
      h = {
        count: f,
        texture: A,
        size: new Ce(_, D)
      }, r.set(o, h), o.addEventListener("dispose", E);
    }
    if (s.isInstancedMesh === !0 && s.morphTexture !== null)
      l.getUniforms().setValue(a, "morphTexture", s.morphTexture, t);
    else {
      let d = 0;
      for (let v = 0; v < c.length; v++)
        d += c[v];
      const g = o.morphTargetsRelative ? 1 : 1 - d;
      l.getUniforms().setValue(a, "morphTargetBaseInfluence", g), l.getUniforms().setValue(a, "morphTargetInfluences", c);
    }
    l.getUniforms().setValue(a, "morphTargetsTexture", h.texture, t), l.getUniforms().setValue(a, "morphTargetsTextureSize", h.size);
  }
  return {
    update: i
  };
}
function qh(a, e, t, r) {
  let n = /* @__PURE__ */ new WeakMap();
  function i(l) {
    const c = r.render.frame, u = l.geometry, f = e.get(l, u);
    if (n.get(f) !== c && (e.update(f), n.set(f, c)), l.isInstancedMesh && (l.hasEventListener("dispose", o) === !1 && l.addEventListener("dispose", o), n.get(l) !== c && (t.update(l.instanceMatrix, a.ARRAY_BUFFER), l.instanceColor !== null && t.update(l.instanceColor, a.ARRAY_BUFFER), n.set(l, c))), l.isSkinnedMesh) {
      const h = l.skeleton;
      n.get(h) !== c && (h.update(), n.set(h, c));
    }
    return f;
  }
  function s() {
    n = /* @__PURE__ */ new WeakMap();
  }
  function o(l) {
    const c = l.target;
    c.removeEventListener("dispose", o), t.remove(c.instanceMatrix), c.instanceColor !== null && t.remove(c.instanceColor);
  }
  return {
    update: i,
    dispose: s
  };
}
class jo extends wt {
  constructor(e, t, r, n, i, s, o, l, c, u = 1026) {
    if (u !== 1026 && u !== 1027)
      throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");
    r === void 0 && u === 1026 && (r = 1014), r === void 0 && u === 1027 && (r = 1020), super(null, n, i, s, o, l, u, r, c), this.isDepthTexture = !0, this.image = { width: e, height: t }, this.magFilter = o !== void 0 ? o : 1003, this.minFilter = l !== void 0 ? l : 1003, this.flipY = !1, this.generateMipmaps = !1, this.compareFunction = null;
  }
  copy(e) {
    return super.copy(e), this.compareFunction = e.compareFunction, this;
  }
  toJSON(e) {
    const t = super.toJSON(e);
    return this.compareFunction !== null && (t.compareFunction = this.compareFunction), t;
  }
}
const Zo = /* @__PURE__ */ new wt(), qs = /* @__PURE__ */ new jo(1, 1), Ko = /* @__PURE__ */ new Oo(), Jo = /* @__PURE__ */ new Ll(), Qo = /* @__PURE__ */ new Wo(), Ys = [], js = [], Zs = new Float32Array(16), Ks = new Float32Array(9), Js = new Float32Array(4);
function _i(a, e, t) {
  const r = a[0];
  if (r <= 0 || r > 0) return a;
  const n = e * t;
  let i = Ys[n];
  if (i === void 0 && (i = new Float32Array(n), Ys[n] = i), e !== 0) {
    r.toArray(i, 0);
    for (let s = 1, o = 0; s !== e; ++s)
      o += t, a[s].toArray(i, o);
  }
  return i;
}
function ft(a, e) {
  if (a.length !== e.length) return !1;
  for (let t = 0, r = a.length; t < r; t++)
    if (a[t] !== e[t]) return !1;
  return !0;
}
function dt(a, e) {
  for (let t = 0, r = e.length; t < r; t++)
    a[t] = e[t];
}
function Gr(a, e) {
  let t = js[e];
  t === void 0 && (t = new Int32Array(e), js[e] = t);
  for (let r = 0; r !== e; ++r)
    t[r] = a.allocateTextureUnit();
  return t;
}
function Yh(a, e) {
  const t = this.cache;
  t[0] !== e && (a.uniform1f(this.addr, e), t[0] = e);
}
function jh(a, e) {
  const t = this.cache;
  if (e.x !== void 0)
    (t[0] !== e.x || t[1] !== e.y) && (a.uniform2f(this.addr, e.x, e.y), t[0] = e.x, t[1] = e.y);
  else {
    if (ft(t, e)) return;
    a.uniform2fv(this.addr, e), dt(t, e);
  }
}
function Zh(a, e) {
  const t = this.cache;
  if (e.x !== void 0)
    (t[0] !== e.x || t[1] !== e.y || t[2] !== e.z) && (a.uniform3f(this.addr, e.x, e.y, e.z), t[0] = e.x, t[1] = e.y, t[2] = e.z);
  else if (e.r !== void 0)
    (t[0] !== e.r || t[1] !== e.g || t[2] !== e.b) && (a.uniform3f(this.addr, e.r, e.g, e.b), t[0] = e.r, t[1] = e.g, t[2] = e.b);
  else {
    if (ft(t, e)) return;
    a.uniform3fv(this.addr, e), dt(t, e);
  }
}
function Kh(a, e) {
  const t = this.cache;
  if (e.x !== void 0)
    (t[0] !== e.x || t[1] !== e.y || t[2] !== e.z || t[3] !== e.w) && (a.uniform4f(this.addr, e.x, e.y, e.z, e.w), t[0] = e.x, t[1] = e.y, t[2] = e.z, t[3] = e.w);
  else {
    if (ft(t, e)) return;
    a.uniform4fv(this.addr, e), dt(t, e);
  }
}
function Jh(a, e) {
  const t = this.cache, r = e.elements;
  if (r === void 0) {
    if (ft(t, e)) return;
    a.uniformMatrix2fv(this.addr, !1, e), dt(t, e);
  } else {
    if (ft(t, r)) return;
    Js.set(r), a.uniformMatrix2fv(this.addr, !1, Js), dt(t, r);
  }
}
function Qh(a, e) {
  const t = this.cache, r = e.elements;
  if (r === void 0) {
    if (ft(t, e)) return;
    a.uniformMatrix3fv(this.addr, !1, e), dt(t, e);
  } else {
    if (ft(t, r)) return;
    Ks.set(r), a.uniformMatrix3fv(this.addr, !1, Ks), dt(t, r);
  }
}
function $h(a, e) {
  const t = this.cache, r = e.elements;
  if (r === void 0) {
    if (ft(t, e)) return;
    a.uniformMatrix4fv(this.addr, !1, e), dt(t, e);
  } else {
    if (ft(t, r)) return;
    Zs.set(r), a.uniformMatrix4fv(this.addr, !1, Zs), dt(t, r);
  }
}
function ef(a, e) {
  const t = this.cache;
  t[0] !== e && (a.uniform1i(this.addr, e), t[0] = e);
}
function tf(a, e) {
  const t = this.cache;
  if (e.x !== void 0)
    (t[0] !== e.x || t[1] !== e.y) && (a.uniform2i(this.addr, e.x, e.y), t[0] = e.x, t[1] = e.y);
  else {
    if (ft(t, e)) return;
    a.uniform2iv(this.addr, e), dt(t, e);
  }
}
function nf(a, e) {
  const t = this.cache;
  if (e.x !== void 0)
    (t[0] !== e.x || t[1] !== e.y || t[2] !== e.z) && (a.uniform3i(this.addr, e.x, e.y, e.z), t[0] = e.x, t[1] = e.y, t[2] = e.z);
  else {
    if (ft(t, e)) return;
    a.uniform3iv(this.addr, e), dt(t, e);
  }
}
function rf(a, e) {
  const t = this.cache;
  if (e.x !== void 0)
    (t[0] !== e.x || t[1] !== e.y || t[2] !== e.z || t[3] !== e.w) && (a.uniform4i(this.addr, e.x, e.y, e.z, e.w), t[0] = e.x, t[1] = e.y, t[2] = e.z, t[3] = e.w);
  else {
    if (ft(t, e)) return;
    a.uniform4iv(this.addr, e), dt(t, e);
  }
}
function af(a, e) {
  const t = this.cache;
  t[0] !== e && (a.uniform1ui(this.addr, e), t[0] = e);
}
function sf(a, e) {
  const t = this.cache;
  if (e.x !== void 0)
    (t[0] !== e.x || t[1] !== e.y) && (a.uniform2ui(this.addr, e.x, e.y), t[0] = e.x, t[1] = e.y);
  else {
    if (ft(t, e)) return;
    a.uniform2uiv(this.addr, e), dt(t, e);
  }
}
function of(a, e) {
  const t = this.cache;
  if (e.x !== void 0)
    (t[0] !== e.x || t[1] !== e.y || t[2] !== e.z) && (a.uniform3ui(this.addr, e.x, e.y, e.z), t[0] = e.x, t[1] = e.y, t[2] = e.z);
  else {
    if (ft(t, e)) return;
    a.uniform3uiv(this.addr, e), dt(t, e);
  }
}
function lf(a, e) {
  const t = this.cache;
  if (e.x !== void 0)
    (t[0] !== e.x || t[1] !== e.y || t[2] !== e.z || t[3] !== e.w) && (a.uniform4ui(this.addr, e.x, e.y, e.z, e.w), t[0] = e.x, t[1] = e.y, t[2] = e.z, t[3] = e.w);
  else {
    if (ft(t, e)) return;
    a.uniform4uiv(this.addr, e), dt(t, e);
  }
}
function cf(a, e, t) {
  const r = this.cache, n = t.allocateTextureUnit();
  r[0] !== n && (a.uniform1i(this.addr, n), r[0] = n);
  let i;
  this.type === a.SAMPLER_2D_SHADOW ? (qs.compareFunction = 515, i = qs) : i = Zo, t.setTexture2D(e || i, n);
}
function uf(a, e, t) {
  const r = this.cache, n = t.allocateTextureUnit();
  r[0] !== n && (a.uniform1i(this.addr, n), r[0] = n), t.setTexture3D(e || Jo, n);
}
function hf(a, e, t) {
  const r = this.cache, n = t.allocateTextureUnit();
  r[0] !== n && (a.uniform1i(this.addr, n), r[0] = n), t.setTextureCube(e || Qo, n);
}
function ff(a, e, t) {
  const r = this.cache, n = t.allocateTextureUnit();
  r[0] !== n && (a.uniform1i(this.addr, n), r[0] = n), t.setTexture2DArray(e || Ko, n);
}
function df(a) {
  switch (a) {
    case 5126:
      return Yh;
    case 35664:
      return jh;
    case 35665:
      return Zh;
    case 35666:
      return Kh;
    case 35674:
      return Jh;
    case 35675:
      return Qh;
    case 35676:
      return $h;
    case 5124:
    case 35670:
      return ef;
    case 35667:
    case 35671:
      return tf;
    case 35668:
    case 35672:
      return nf;
    case 35669:
    case 35673:
      return rf;
    case 5125:
      return af;
    case 36294:
      return sf;
    case 36295:
      return of;
    case 36296:
      return lf;
    case 35678:
    case 36198:
    case 36298:
    case 36306:
    case 35682:
      return cf;
    case 35679:
    case 36299:
    case 36307:
      return uf;
    case 35680:
    case 36300:
    case 36308:
    case 36293:
      return hf;
    case 36289:
    case 36303:
    case 36311:
    case 36292:
      return ff;
  }
}
function pf(a, e) {
  a.uniform1fv(this.addr, e);
}
function mf(a, e) {
  const t = _i(e, this.size, 2);
  a.uniform2fv(this.addr, t);
}
function gf(a, e) {
  const t = _i(e, this.size, 3);
  a.uniform3fv(this.addr, t);
}
function vf(a, e) {
  const t = _i(e, this.size, 4);
  a.uniform4fv(this.addr, t);
}
function _f(a, e) {
  const t = _i(e, this.size, 4);
  a.uniformMatrix2fv(this.addr, !1, t);
}
function xf(a, e) {
  const t = _i(e, this.size, 9);
  a.uniformMatrix3fv(this.addr, !1, t);
}
function Sf(a, e) {
  const t = _i(e, this.size, 16);
  a.uniformMatrix4fv(this.addr, !1, t);
}
function yf(a, e) {
  a.uniform1iv(this.addr, e);
}
function Mf(a, e) {
  a.uniform2iv(this.addr, e);
}
function Ef(a, e) {
  a.uniform3iv(this.addr, e);
}
function Tf(a, e) {
  a.uniform4iv(this.addr, e);
}
function bf(a, e) {
  a.uniform1uiv(this.addr, e);
}
function Af(a, e) {
  a.uniform2uiv(this.addr, e);
}
function wf(a, e) {
  a.uniform3uiv(this.addr, e);
}
function Cf(a, e) {
  a.uniform4uiv(this.addr, e);
}
function Rf(a, e, t) {
  const r = this.cache, n = e.length, i = Gr(t, n);
  ft(r, i) || (a.uniform1iv(this.addr, i), dt(r, i));
  for (let s = 0; s !== n; ++s)
    t.setTexture2D(e[s] || Zo, i[s]);
}
function Pf(a, e, t) {
  const r = this.cache, n = e.length, i = Gr(t, n);
  ft(r, i) || (a.uniform1iv(this.addr, i), dt(r, i));
  for (let s = 0; s !== n; ++s)
    t.setTexture3D(e[s] || Jo, i[s]);
}
function Uf(a, e, t) {
  const r = this.cache, n = e.length, i = Gr(t, n);
  ft(r, i) || (a.uniform1iv(this.addr, i), dt(r, i));
  for (let s = 0; s !== n; ++s)
    t.setTextureCube(e[s] || Qo, i[s]);
}
function Df(a, e, t) {
  const r = this.cache, n = e.length, i = Gr(t, n);
  ft(r, i) || (a.uniform1iv(this.addr, i), dt(r, i));
  for (let s = 0; s !== n; ++s)
    t.setTexture2DArray(e[s] || Ko, i[s]);
}
function Lf(a) {
  switch (a) {
    case 5126:
      return pf;
    case 35664:
      return mf;
    case 35665:
      return gf;
    case 35666:
      return vf;
    case 35674:
      return _f;
    case 35675:
      return xf;
    case 35676:
      return Sf;
    case 5124:
    case 35670:
      return yf;
    case 35667:
    case 35671:
      return Mf;
    case 35668:
    case 35672:
      return Ef;
    case 35669:
    case 35673:
      return Tf;
    case 5125:
      return bf;
    case 36294:
      return Af;
    case 36295:
      return wf;
    case 36296:
      return Cf;
    case 35678:
    case 36198:
    case 36298:
    case 36306:
    case 35682:
      return Rf;
    case 35679:
    case 36299:
    case 36307:
      return Pf;
    case 35680:
    case 36300:
    case 36308:
    case 36293:
      return Uf;
    case 36289:
    case 36303:
    case 36311:
    case 36292:
      return Df;
  }
}
class Ff {
  constructor(e, t, r) {
    this.id = e, this.addr = r, this.cache = [], this.type = t.type, this.setValue = df(t.type);
  }
}
class If {
  constructor(e, t, r) {
    this.id = e, this.addr = r, this.cache = [], this.type = t.type, this.size = t.size, this.setValue = Lf(t.type);
  }
}
class Nf {
  constructor(e) {
    this.id = e, this.seq = [], this.map = {};
  }
  setValue(e, t, r) {
    const n = this.seq;
    for (let i = 0, s = n.length; i !== s; ++i) {
      const o = n[i];
      o.setValue(e, t[o.id], r);
    }
  }
}
const Ra = /(\w+)(\])?(\[|\.)?/g;
function Qs(a, e) {
  a.seq.push(e), a.map[e.id] = e;
}
function Of(a, e, t) {
  const r = a.name, n = r.length;
  for (Ra.lastIndex = 0; ; ) {
    const i = Ra.exec(r), s = Ra.lastIndex;
    let o = i[1];
    const l = i[2] === "]", c = i[3];
    if (l && (o = o | 0), c === void 0 || c === "[" && s + 2 === n) {
      Qs(t, c === void 0 ? new Ff(o, a, e) : new If(o, a, e));
      break;
    } else {
      let f = t.map[o];
      f === void 0 && (f = new Nf(o), Qs(t, f)), t = f;
    }
  }
}
class Dr {
  constructor(e, t) {
    this.seq = [], this.map = {};
    const r = e.getProgramParameter(t, e.ACTIVE_UNIFORMS);
    for (let n = 0; n < r; ++n) {
      const i = e.getActiveUniform(t, n), s = e.getUniformLocation(t, i.name);
      Of(i, s, this);
    }
  }
  setValue(e, t, r, n) {
    const i = this.map[t];
    i !== void 0 && i.setValue(e, r, n);
  }
  setOptional(e, t, r) {
    const n = t[r];
    n !== void 0 && this.setValue(e, r, n);
  }
  static upload(e, t, r, n) {
    for (let i = 0, s = t.length; i !== s; ++i) {
      const o = t[i], l = r[o.id];
      l.needsUpdate !== !1 && o.setValue(e, l.value, n);
    }
  }
  static seqWithValue(e, t) {
    const r = [];
    for (let n = 0, i = e.length; n !== i; ++n) {
      const s = e[n];
      s.id in t && r.push(s);
    }
    return r;
  }
}
function $s(a, e, t) {
  const r = a.createShader(e);
  return a.shaderSource(r, t), a.compileShader(r), r;
}
const Bf = 37297;
let kf = 0;
function Gf(a, e) {
  const t = a.split(`
`), r = [], n = Math.max(e - 6, 0), i = Math.min(e + 6, t.length);
  for (let s = n; s < i; s++) {
    const o = s + 1;
    r.push(`${o === e ? ">" : " "} ${o}: ${t[s]}`);
  }
  return r.join(`
`);
}
const eo = /* @__PURE__ */ new Ye();
function zf(a) {
  $e._getMatrix(eo, $e.workingColorSpace, a);
  const e = `mat3( ${eo.elements.map((t) => t.toFixed(4))} )`;
  switch ($e.getTransfer(a)) {
    case kr:
      return [e, "LinearTransferOETF"];
    case it:
      return [e, "sRGBTransferOETF"];
    default:
      return console.warn("THREE.WebGLProgram: Unsupported color space: ", a), [e, "LinearTransferOETF"];
  }
}
function to(a, e, t) {
  const r = a.getShaderParameter(e, a.COMPILE_STATUS), n = a.getShaderInfoLog(e).trim();
  if (r && n === "") return "";
  const i = /ERROR: 0:(\d+)/.exec(n);
  if (i) {
    const s = parseInt(i[1]);
    return t.toUpperCase() + `

` + n + `

` + Gf(a.getShaderSource(e), s);
  } else
    return n;
}
function Vf(a, e) {
  const t = zf(e);
  return [
    `vec4 ${a}( vec4 value ) {`,
    `	return ${t[1]}( vec4( value.rgb * ${t[0]}, value.a ) );`,
    "}"
  ].join(`
`);
}
function Hf(a, e) {
  let t;
  switch (e) {
    case 1:
      t = "Linear";
      break;
    case 2:
      t = "Reinhard";
      break;
    case 3:
      t = "Cineon";
      break;
    case 4:
      t = "ACESFilmic";
      break;
    case 6:
      t = "AgX";
      break;
    case 7:
      t = "Neutral";
      break;
    case 5:
      t = "Custom";
      break;
    default:
      console.warn("THREE.WebGLProgram: Unsupported toneMapping:", e), t = "Linear";
  }
  return "vec3 " + a + "( vec3 color ) { return " + t + "ToneMapping( color ); }";
}
const Sr = /* @__PURE__ */ new j();
function Wf() {
  $e.getLuminanceCoefficients(Sr);
  const a = Sr.x.toFixed(4), e = Sr.y.toFixed(4), t = Sr.z.toFixed(4);
  return [
    "float luminance( const in vec3 rgb ) {",
    `	const vec3 weights = vec3( ${a}, ${e}, ${t} );`,
    "	return dot( weights, rgb );",
    "}"
  ].join(`
`);
}
function Xf(a) {
  return [
    a.extensionClipCullDistance ? "#extension GL_ANGLE_clip_cull_distance : require" : "",
    a.extensionMultiDraw ? "#extension GL_ANGLE_multi_draw : require" : ""
  ].filter(Oi).join(`
`);
}
function qf(a) {
  const e = [];
  for (const t in a) {
    const r = a[t];
    r !== !1 && e.push("#define " + t + " " + r);
  }
  return e.join(`
`);
}
function Yf(a, e) {
  const t = {}, r = a.getProgramParameter(e, a.ACTIVE_ATTRIBUTES);
  for (let n = 0; n < r; n++) {
    const i = a.getActiveAttrib(e, n), s = i.name;
    let o = 1;
    i.type === a.FLOAT_MAT2 && (o = 2), i.type === a.FLOAT_MAT3 && (o = 3), i.type === a.FLOAT_MAT4 && (o = 4), t[s] = {
      type: i.type,
      location: a.getAttribLocation(e, s),
      locationSize: o
    };
  }
  return t;
}
function Oi(a) {
  return a !== "";
}
function no(a, e) {
  const t = e.numSpotLightShadows + e.numSpotLightMaps - e.numSpotLightShadowsWithMaps;
  return a.replace(/NUM_DIR_LIGHTS/g, e.numDirLights).replace(/NUM_SPOT_LIGHTS/g, e.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g, e.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g, t).replace(/NUM_RECT_AREA_LIGHTS/g, e.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g, e.numPointLights).replace(/NUM_HEMI_LIGHTS/g, e.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g, e.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g, e.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g, e.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g, e.numPointLightShadows);
}
function io(a, e) {
  return a.replace(/NUM_CLIPPING_PLANES/g, e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, e.numClippingPlanes - e.numClipIntersection);
}
const jf = /^[ \t]*#include +<([\w\d./]+)>/gm;
function Ga(a) {
  return a.replace(jf, Kf);
}
const Zf = /* @__PURE__ */ new Map();
function Kf(a, e) {
  let t = Xe[e];
  if (t === void 0) {
    const r = Zf.get(e);
    if (r !== void 0)
      t = Xe[r], console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.', e, r);
    else
      throw new Error("Can not resolve #include <" + e + ">");
  }
  return Ga(t);
}
const Jf = /#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;
function ro(a) {
  return a.replace(Jf, Qf);
}
function Qf(a, e, t, r) {
  let n = "";
  for (let i = parseInt(e); i < parseInt(t); i++)
    n += r.replace(/\[\s*i\s*\]/g, "[ " + i + " ]").replace(/UNROLLED_LOOP_INDEX/g, i);
  return n;
}
function ao(a) {
  let e = `precision ${a.precision} float;
	precision ${a.precision} int;
	precision ${a.precision} sampler2D;
	precision ${a.precision} samplerCube;
	precision ${a.precision} sampler3D;
	precision ${a.precision} sampler2DArray;
	precision ${a.precision} sampler2DShadow;
	precision ${a.precision} samplerCubeShadow;
	precision ${a.precision} sampler2DArrayShadow;
	precision ${a.precision} isampler2D;
	precision ${a.precision} isampler3D;
	precision ${a.precision} isamplerCube;
	precision ${a.precision} isampler2DArray;
	precision ${a.precision} usampler2D;
	precision ${a.precision} usampler3D;
	precision ${a.precision} usamplerCube;
	precision ${a.precision} usampler2DArray;
	`;
  return a.precision === "highp" ? e += `
#define HIGH_PRECISION` : a.precision === "mediump" ? e += `
#define MEDIUM_PRECISION` : a.precision === "lowp" && (e += `
#define LOW_PRECISION`), e;
}
function $f(a) {
  let e = "SHADOWMAP_TYPE_BASIC";
  return a.shadowMapType === 1 ? e = "SHADOWMAP_TYPE_PCF" : a.shadowMapType === 2 ? e = "SHADOWMAP_TYPE_PCF_SOFT" : a.shadowMapType === 3 && (e = "SHADOWMAP_TYPE_VSM"), e;
}
function ed(a) {
  let e = "ENVMAP_TYPE_CUBE";
  if (a.envMap)
    switch (a.envMapMode) {
      case 301:
      case 302:
        e = "ENVMAP_TYPE_CUBE";
        break;
      case 306:
        e = "ENVMAP_TYPE_CUBE_UV";
        break;
    }
  return e;
}
function td(a) {
  let e = "ENVMAP_MODE_REFLECTION";
  if (a.envMap)
    switch (a.envMapMode) {
      case 302:
        e = "ENVMAP_MODE_REFRACTION";
        break;
    }
  return e;
}
function nd(a) {
  let e = "ENVMAP_BLENDING_NONE";
  if (a.envMap)
    switch (a.combine) {
      case 0:
        e = "ENVMAP_BLENDING_MULTIPLY";
        break;
      case 1:
        e = "ENVMAP_BLENDING_MIX";
        break;
      case 2:
        e = "ENVMAP_BLENDING_ADD";
        break;
    }
  return e;
}
function id(a) {
  const e = a.envMapCubeUVHeight;
  if (e === null) return null;
  const t = Math.log2(e) - 2, r = 1 / e;
  return { texelWidth: 1 / (3 * Math.max(Math.pow(2, t), 7 * 16)), texelHeight: r, maxMip: t };
}
function rd(a, e, t, r) {
  const n = a.getContext(), i = t.defines;
  let s = t.vertexShader, o = t.fragmentShader;
  const l = $f(t), c = ed(t), u = td(t), f = nd(t), h = id(t), d = Xf(t), g = qf(i), v = n.createProgram();
  let m, p, T = t.glslVersion ? "#version " + t.glslVersion + `
` : "";
  t.isRawShaderMaterial ? (m = [
    "#define SHADER_TYPE " + t.shaderType,
    "#define SHADER_NAME " + t.shaderName,
    g
  ].filter(Oi).join(`
`), m.length > 0 && (m += `
`), p = [
    "#define SHADER_TYPE " + t.shaderType,
    "#define SHADER_NAME " + t.shaderName,
    g
  ].filter(Oi).join(`
`), p.length > 0 && (p += `
`)) : (m = [
    ao(t),
    "#define SHADER_TYPE " + t.shaderType,
    "#define SHADER_NAME " + t.shaderName,
    g,
    t.extensionClipCullDistance ? "#define USE_CLIP_DISTANCE" : "",
    t.batching ? "#define USE_BATCHING" : "",
    t.batchingColor ? "#define USE_BATCHING_COLOR" : "",
    t.instancing ? "#define USE_INSTANCING" : "",
    t.instancingColor ? "#define USE_INSTANCING_COLOR" : "",
    t.instancingMorph ? "#define USE_INSTANCING_MORPH" : "",
    t.useFog && t.fog ? "#define USE_FOG" : "",
    t.useFog && t.fogExp2 ? "#define FOG_EXP2" : "",
    t.map ? "#define USE_MAP" : "",
    t.envMap ? "#define USE_ENVMAP" : "",
    t.envMap ? "#define " + u : "",
    t.lightMap ? "#define USE_LIGHTMAP" : "",
    t.aoMap ? "#define USE_AOMAP" : "",
    t.bumpMap ? "#define USE_BUMPMAP" : "",
    t.normalMap ? "#define USE_NORMALMAP" : "",
    t.normalMapObjectSpace ? "#define USE_NORMALMAP_OBJECTSPACE" : "",
    t.normalMapTangentSpace ? "#define USE_NORMALMAP_TANGENTSPACE" : "",
    t.displacementMap ? "#define USE_DISPLACEMENTMAP" : "",
    t.emissiveMap ? "#define USE_EMISSIVEMAP" : "",
    t.anisotropy ? "#define USE_ANISOTROPY" : "",
    t.anisotropyMap ? "#define USE_ANISOTROPYMAP" : "",
    t.clearcoatMap ? "#define USE_CLEARCOATMAP" : "",
    t.clearcoatRoughnessMap ? "#define USE_CLEARCOAT_ROUGHNESSMAP" : "",
    t.clearcoatNormalMap ? "#define USE_CLEARCOAT_NORMALMAP" : "",
    t.iridescenceMap ? "#define USE_IRIDESCENCEMAP" : "",
    t.iridescenceThicknessMap ? "#define USE_IRIDESCENCE_THICKNESSMAP" : "",
    t.specularMap ? "#define USE_SPECULARMAP" : "",
    t.specularColorMap ? "#define USE_SPECULAR_COLORMAP" : "",
    t.specularIntensityMap ? "#define USE_SPECULAR_INTENSITYMAP" : "",
    t.roughnessMap ? "#define USE_ROUGHNESSMAP" : "",
    t.metalnessMap ? "#define USE_METALNESSMAP" : "",
    t.alphaMap ? "#define USE_ALPHAMAP" : "",
    t.alphaHash ? "#define USE_ALPHAHASH" : "",
    t.transmission ? "#define USE_TRANSMISSION" : "",
    t.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "",
    t.thicknessMap ? "#define USE_THICKNESSMAP" : "",
    t.sheenColorMap ? "#define USE_SHEEN_COLORMAP" : "",
    t.sheenRoughnessMap ? "#define USE_SHEEN_ROUGHNESSMAP" : "",
    //
    t.mapUv ? "#define MAP_UV " + t.mapUv : "",
    t.alphaMapUv ? "#define ALPHAMAP_UV " + t.alphaMapUv : "",
    t.lightMapUv ? "#define LIGHTMAP_UV " + t.lightMapUv : "",
    t.aoMapUv ? "#define AOMAP_UV " + t.aoMapUv : "",
    t.emissiveMapUv ? "#define EMISSIVEMAP_UV " + t.emissiveMapUv : "",
    t.bumpMapUv ? "#define BUMPMAP_UV " + t.bumpMapUv : "",
    t.normalMapUv ? "#define NORMALMAP_UV " + t.normalMapUv : "",
    t.displacementMapUv ? "#define DISPLACEMENTMAP_UV " + t.displacementMapUv : "",
    t.metalnessMapUv ? "#define METALNESSMAP_UV " + t.metalnessMapUv : "",
    t.roughnessMapUv ? "#define ROUGHNESSMAP_UV " + t.roughnessMapUv : "",
    t.anisotropyMapUv ? "#define ANISOTROPYMAP_UV " + t.anisotropyMapUv : "",
    t.clearcoatMapUv ? "#define CLEARCOATMAP_UV " + t.clearcoatMapUv : "",
    t.clearcoatNormalMapUv ? "#define CLEARCOAT_NORMALMAP_UV " + t.clearcoatNormalMapUv : "",
    t.clearcoatRoughnessMapUv ? "#define CLEARCOAT_ROUGHNESSMAP_UV " + t.clearcoatRoughnessMapUv : "",
    t.iridescenceMapUv ? "#define IRIDESCENCEMAP_UV " + t.iridescenceMapUv : "",
    t.iridescenceThicknessMapUv ? "#define IRIDESCENCE_THICKNESSMAP_UV " + t.iridescenceThicknessMapUv : "",
    t.sheenColorMapUv ? "#define SHEEN_COLORMAP_UV " + t.sheenColorMapUv : "",
    t.sheenRoughnessMapUv ? "#define SHEEN_ROUGHNESSMAP_UV " + t.sheenRoughnessMapUv : "",
    t.specularMapUv ? "#define SPECULARMAP_UV " + t.specularMapUv : "",
    t.specularColorMapUv ? "#define SPECULAR_COLORMAP_UV " + t.specularColorMapUv : "",
    t.specularIntensityMapUv ? "#define SPECULAR_INTENSITYMAP_UV " + t.specularIntensityMapUv : "",
    t.transmissionMapUv ? "#define TRANSMISSIONMAP_UV " + t.transmissionMapUv : "",
    t.thicknessMapUv ? "#define THICKNESSMAP_UV " + t.thicknessMapUv : "",
    //
    t.vertexTangents && t.flatShading === !1 ? "#define USE_TANGENT" : "",
    t.vertexColors ? "#define USE_COLOR" : "",
    t.vertexAlphas ? "#define USE_COLOR_ALPHA" : "",
    t.vertexUv1s ? "#define USE_UV1" : "",
    t.vertexUv2s ? "#define USE_UV2" : "",
    t.vertexUv3s ? "#define USE_UV3" : "",
    t.pointsUvs ? "#define USE_POINTS_UV" : "",
    t.flatShading ? "#define FLAT_SHADED" : "",
    t.skinning ? "#define USE_SKINNING" : "",
    t.morphTargets ? "#define USE_MORPHTARGETS" : "",
    t.morphNormals && t.flatShading === !1 ? "#define USE_MORPHNORMALS" : "",
    t.morphColors ? "#define USE_MORPHCOLORS" : "",
    t.morphTargetsCount > 0 ? "#define MORPHTARGETS_TEXTURE_STRIDE " + t.morphTextureStride : "",
    t.morphTargetsCount > 0 ? "#define MORPHTARGETS_COUNT " + t.morphTargetsCount : "",
    t.doubleSided ? "#define DOUBLE_SIDED" : "",
    t.flipSided ? "#define FLIP_SIDED" : "",
    t.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
    t.shadowMapEnabled ? "#define " + l : "",
    t.sizeAttenuation ? "#define USE_SIZEATTENUATION" : "",
    t.numLightProbes > 0 ? "#define USE_LIGHT_PROBES" : "",
    t.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "",
    t.reverseDepthBuffer ? "#define USE_REVERSEDEPTHBUF" : "",
    "uniform mat4 modelMatrix;",
    "uniform mat4 modelViewMatrix;",
    "uniform mat4 projectionMatrix;",
    "uniform mat4 viewMatrix;",
    "uniform mat3 normalMatrix;",
    "uniform vec3 cameraPosition;",
    "uniform bool isOrthographic;",
    "#ifdef USE_INSTANCING",
    "	attribute mat4 instanceMatrix;",
    "#endif",
    "#ifdef USE_INSTANCING_COLOR",
    "	attribute vec3 instanceColor;",
    "#endif",
    "#ifdef USE_INSTANCING_MORPH",
    "	uniform sampler2D morphTexture;",
    "#endif",
    "attribute vec3 position;",
    "attribute vec3 normal;",
    "attribute vec2 uv;",
    "#ifdef USE_UV1",
    "	attribute vec2 uv1;",
    "#endif",
    "#ifdef USE_UV2",
    "	attribute vec2 uv2;",
    "#endif",
    "#ifdef USE_UV3",
    "	attribute vec2 uv3;",
    "#endif",
    "#ifdef USE_TANGENT",
    "	attribute vec4 tangent;",
    "#endif",
    "#if defined( USE_COLOR_ALPHA )",
    "	attribute vec4 color;",
    "#elif defined( USE_COLOR )",
    "	attribute vec3 color;",
    "#endif",
    "#ifdef USE_SKINNING",
    "	attribute vec4 skinIndex;",
    "	attribute vec4 skinWeight;",
    "#endif",
    `
`
  ].filter(Oi).join(`
`), p = [
    ao(t),
    "#define SHADER_TYPE " + t.shaderType,
    "#define SHADER_NAME " + t.shaderName,
    g,
    t.useFog && t.fog ? "#define USE_FOG" : "",
    t.useFog && t.fogExp2 ? "#define FOG_EXP2" : "",
    t.alphaToCoverage ? "#define ALPHA_TO_COVERAGE" : "",
    t.map ? "#define USE_MAP" : "",
    t.matcap ? "#define USE_MATCAP" : "",
    t.envMap ? "#define USE_ENVMAP" : "",
    t.envMap ? "#define " + c : "",
    t.envMap ? "#define " + u : "",
    t.envMap ? "#define " + f : "",
    h ? "#define CUBEUV_TEXEL_WIDTH " + h.texelWidth : "",
    h ? "#define CUBEUV_TEXEL_HEIGHT " + h.texelHeight : "",
    h ? "#define CUBEUV_MAX_MIP " + h.maxMip + ".0" : "",
    t.lightMap ? "#define USE_LIGHTMAP" : "",
    t.aoMap ? "#define USE_AOMAP" : "",
    t.bumpMap ? "#define USE_BUMPMAP" : "",
    t.normalMap ? "#define USE_NORMALMAP" : "",
    t.normalMapObjectSpace ? "#define USE_NORMALMAP_OBJECTSPACE" : "",
    t.normalMapTangentSpace ? "#define USE_NORMALMAP_TANGENTSPACE" : "",
    t.emissiveMap ? "#define USE_EMISSIVEMAP" : "",
    t.anisotropy ? "#define USE_ANISOTROPY" : "",
    t.anisotropyMap ? "#define USE_ANISOTROPYMAP" : "",
    t.clearcoat ? "#define USE_CLEARCOAT" : "",
    t.clearcoatMap ? "#define USE_CLEARCOATMAP" : "",
    t.clearcoatRoughnessMap ? "#define USE_CLEARCOAT_ROUGHNESSMAP" : "",
    t.clearcoatNormalMap ? "#define USE_CLEARCOAT_NORMALMAP" : "",
    t.dispersion ? "#define USE_DISPERSION" : "",
    t.iridescence ? "#define USE_IRIDESCENCE" : "",
    t.iridescenceMap ? "#define USE_IRIDESCENCEMAP" : "",
    t.iridescenceThicknessMap ? "#define USE_IRIDESCENCE_THICKNESSMAP" : "",
    t.specularMap ? "#define USE_SPECULARMAP" : "",
    t.specularColorMap ? "#define USE_SPECULAR_COLORMAP" : "",
    t.specularIntensityMap ? "#define USE_SPECULAR_INTENSITYMAP" : "",
    t.roughnessMap ? "#define USE_ROUGHNESSMAP" : "",
    t.metalnessMap ? "#define USE_METALNESSMAP" : "",
    t.alphaMap ? "#define USE_ALPHAMAP" : "",
    t.alphaTest ? "#define USE_ALPHATEST" : "",
    t.alphaHash ? "#define USE_ALPHAHASH" : "",
    t.sheen ? "#define USE_SHEEN" : "",
    t.sheenColorMap ? "#define USE_SHEEN_COLORMAP" : "",
    t.sheenRoughnessMap ? "#define USE_SHEEN_ROUGHNESSMAP" : "",
    t.transmission ? "#define USE_TRANSMISSION" : "",
    t.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "",
    t.thicknessMap ? "#define USE_THICKNESSMAP" : "",
    t.vertexTangents && t.flatShading === !1 ? "#define USE_TANGENT" : "",
    t.vertexColors || t.instancingColor || t.batchingColor ? "#define USE_COLOR" : "",
    t.vertexAlphas ? "#define USE_COLOR_ALPHA" : "",
    t.vertexUv1s ? "#define USE_UV1" : "",
    t.vertexUv2s ? "#define USE_UV2" : "",
    t.vertexUv3s ? "#define USE_UV3" : "",
    t.pointsUvs ? "#define USE_POINTS_UV" : "",
    t.gradientMap ? "#define USE_GRADIENTMAP" : "",
    t.flatShading ? "#define FLAT_SHADED" : "",
    t.doubleSided ? "#define DOUBLE_SIDED" : "",
    t.flipSided ? "#define FLIP_SIDED" : "",
    t.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
    t.shadowMapEnabled ? "#define " + l : "",
    t.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : "",
    t.numLightProbes > 0 ? "#define USE_LIGHT_PROBES" : "",
    t.decodeVideoTexture ? "#define DECODE_VIDEO_TEXTURE" : "",
    t.decodeVideoTextureEmissive ? "#define DECODE_VIDEO_TEXTURE_EMISSIVE" : "",
    t.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "",
    t.reverseDepthBuffer ? "#define USE_REVERSEDEPTHBUF" : "",
    "uniform mat4 viewMatrix;",
    "uniform vec3 cameraPosition;",
    "uniform bool isOrthographic;",
    t.toneMapping !== 0 ? "#define TONE_MAPPING" : "",
    t.toneMapping !== 0 ? Xe.tonemapping_pars_fragment : "",
    // this code is required here because it is used by the toneMapping() function defined below
    t.toneMapping !== 0 ? Hf("toneMapping", t.toneMapping) : "",
    t.dithering ? "#define DITHERING" : "",
    t.opaque ? "#define OPAQUE" : "",
    Xe.colorspace_pars_fragment,
    // this code is required here because it is used by the various encoding/decoding function defined below
    Vf("linearToOutputTexel", t.outputColorSpace),
    Wf(),
    t.useDepthPacking ? "#define DEPTH_PACKING " + t.depthPacking : "",
    `
`
  ].filter(Oi).join(`
`)), s = Ga(s), s = no(s, t), s = io(s, t), o = Ga(o), o = no(o, t), o = io(o, t), s = ro(s), o = ro(o), t.isRawShaderMaterial !== !0 && (T = `#version 300 es
`, m = [
    d,
    "#define attribute in",
    "#define varying out",
    "#define texture2D texture"
  ].join(`
`) + `
` + m, p = [
    "#define varying in",
    t.glslVersion === _s ? "" : "layout(location = 0) out highp vec4 pc_fragColor;",
    t.glslVersion === _s ? "" : "#define gl_FragColor pc_fragColor",
    "#define gl_FragDepthEXT gl_FragDepth",
    "#define texture2D texture",
    "#define textureCube texture",
    "#define texture2DProj textureProj",
    "#define texture2DLodEXT textureLod",
    "#define texture2DProjLodEXT textureProjLod",
    "#define textureCubeLodEXT textureLod",
    "#define texture2DGradEXT textureGrad",
    "#define texture2DProjGradEXT textureProjGrad",
    "#define textureCubeGradEXT textureGrad"
  ].join(`
`) + `
` + p);
  const x = T + m + s, _ = T + p + o, D = $s(n, n.VERTEX_SHADER, x), C = $s(n, n.FRAGMENT_SHADER, _);
  n.attachShader(v, D), n.attachShader(v, C), t.index0AttributeName !== void 0 ? n.bindAttribLocation(v, 0, t.index0AttributeName) : t.morphTargets === !0 && n.bindAttribLocation(v, 0, "position"), n.linkProgram(v);
  function A(F) {
    if (a.debug.checkShaderErrors) {
      const L = n.getProgramInfoLog(v).trim(), B = n.getShaderInfoLog(D).trim(), k = n.getShaderInfoLog(C).trim();
      let O = !0, z = !0;
      if (n.getProgramParameter(v, n.LINK_STATUS) === !1)
        if (O = !1, typeof a.debug.onShaderError == "function")
          a.debug.onShaderError(n, v, D, C);
        else {
          const ne = to(n, D, "vertex"), q = to(n, C, "fragment");
          console.error(
            "THREE.WebGLProgram: Shader Error " + n.getError() + " - VALIDATE_STATUS " + n.getProgramParameter(v, n.VALIDATE_STATUS) + `

Material Name: ` + F.name + `
Material Type: ` + F.type + `

Program Info Log: ` + L + `
` + ne + `
` + q
          );
        }
      else L !== "" ? console.warn("THREE.WebGLProgram: Program Info Log:", L) : (B === "" || k === "") && (z = !1);
      z && (F.diagnostics = {
        runnable: O,
        programLog: L,
        vertexShader: {
          log: B,
          prefix: m
        },
        fragmentShader: {
          log: k,
          prefix: p
        }
      });
    }
    n.deleteShader(D), n.deleteShader(C), R = new Dr(n, v), E = Yf(n, v);
  }
  let R;
  this.getUniforms = function() {
    return R === void 0 && A(this), R;
  };
  let E;
  this.getAttributes = function() {
    return E === void 0 && A(this), E;
  };
  let S = t.rendererExtensionParallelShaderCompile === !1;
  return this.isReady = function() {
    return S === !1 && (S = n.getProgramParameter(v, Bf)), S;
  }, this.destroy = function() {
    r.releaseStatesOfProgram(this), n.deleteProgram(v), this.program = void 0;
  }, this.type = t.shaderType, this.name = t.shaderName, this.id = kf++, this.cacheKey = e, this.usedTimes = 1, this.program = v, this.vertexShader = D, this.fragmentShader = C, this;
}
let ad = 0;
class sd {
  constructor() {
    this.shaderCache = /* @__PURE__ */ new Map(), this.materialCache = /* @__PURE__ */ new Map();
  }
  update(e) {
    const t = e.vertexShader, r = e.fragmentShader, n = this._getShaderStage(t), i = this._getShaderStage(r), s = this._getShaderCacheForMaterial(e);
    return s.has(n) === !1 && (s.add(n), n.usedTimes++), s.has(i) === !1 && (s.add(i), i.usedTimes++), this;
  }
  remove(e) {
    const t = this.materialCache.get(e);
    for (const r of t)
      r.usedTimes--, r.usedTimes === 0 && this.shaderCache.delete(r.code);
    return this.materialCache.delete(e), this;
  }
  getVertexShaderID(e) {
    return this._getShaderStage(e.vertexShader).id;
  }
  getFragmentShaderID(e) {
    return this._getShaderStage(e.fragmentShader).id;
  }
  dispose() {
    this.shaderCache.clear(), this.materialCache.clear();
  }
  _getShaderCacheForMaterial(e) {
    const t = this.materialCache;
    let r = t.get(e);
    return r === void 0 && (r = /* @__PURE__ */ new Set(), t.set(e, r)), r;
  }
  _getShaderStage(e) {
    const t = this.shaderCache;
    let r = t.get(e);
    return r === void 0 && (r = new od(e), t.set(e, r)), r;
  }
}
class od {
  constructor(e) {
    this.id = ad++, this.code = e, this.usedTimes = 0;
  }
}
function ld(a, e, t, r, n, i, s) {
  const o = new Bo(), l = new sd(), c = /* @__PURE__ */ new Set(), u = [], f = n.logarithmicDepthBuffer, h = n.vertexTextures;
  let d = n.precision;
  const g = {
    MeshDepthMaterial: "depth",
    MeshDistanceMaterial: "distanceRGBA",
    MeshNormalMaterial: "normal",
    MeshBasicMaterial: "basic",
    MeshLambertMaterial: "lambert",
    MeshPhongMaterial: "phong",
    MeshToonMaterial: "toon",
    MeshStandardMaterial: "physical",
    MeshPhysicalMaterial: "physical",
    MeshMatcapMaterial: "matcap",
    LineBasicMaterial: "basic",
    LineDashedMaterial: "dashed",
    PointsMaterial: "points",
    ShadowMaterial: "shadow",
    SpriteMaterial: "sprite"
  };
  function v(E) {
    return c.add(E), E === 0 ? "uv" : `uv${E}`;
  }
  function m(E, S, F, L, B) {
    const k = L.fog, O = B.geometry, z = E.isMeshStandardMaterial ? L.environment : null, ne = (E.isMeshStandardMaterial ? t : e).get(E.envMap || z), q = ne && ne.mapping === 306 ? ne.image.height : null, K = g[E.type];
    E.precision !== null && (d = n.getMaxPrecision(E.precision), d !== E.precision && console.warn("THREE.WebGLProgram.getParameters:", E.precision, "not supported, using", d, "instead."));
    const Z = O.morphAttributes.position || O.morphAttributes.normal || O.morphAttributes.color, N = Z !== void 0 ? Z.length : 0;
    let Y = 0;
    O.morphAttributes.position !== void 0 && (Y = 1), O.morphAttributes.normal !== void 0 && (Y = 2), O.morphAttributes.color !== void 0 && (Y = 3);
    let ie, b, U, G;
    if (K) {
      const Ve = an[K];
      ie = Ve.vertexShader, b = Ve.fragmentShader;
    } else
      ie = E.vertexShader, b = E.fragmentShader, l.update(E), U = l.getVertexShaderID(E), G = l.getFragmentShaderID(E);
    const I = a.getRenderTarget(), V = a.state.buffers.depth.getReversed(), re = B.isInstancedMesh === !0, he = B.isBatchedMesh === !0, fe = !!E.map, W = !!E.matcap, ce = !!ne, P = !!E.aoMap, pe = !!E.lightMap, ae = !!E.bumpMap, ve = !!E.normalMap, te = !!E.displacementMap, Te = !!E.emissiveMap, me = !!E.metalnessMap, M = !!E.roughnessMap, y = E.anisotropy > 0, H = E.clearcoat > 0, $ = E.dispersion > 0, ee = E.iridescence > 0, oe = E.sheen > 0, Se = E.transmission > 0, de = y && !!E.anisotropyMap, xe = H && !!E.clearcoatMap, De = H && !!E.clearcoatNormalMap, ye = H && !!E.clearcoatRoughnessMap, Re = ee && !!E.iridescenceMap, Pe = ee && !!E.iridescenceThicknessMap, Ue = oe && !!E.sheenColorMap, Me = oe && !!E.sheenRoughnessMap, ze = !!E.specularMap, Fe = !!E.specularColorMap, je = !!E.specularIntensityMap, X = Se && !!E.transmissionMap, _e = Se && !!E.thicknessMap, se = !!E.gradientMap, Ee = !!E.alphaMap, Ae = E.alphaTest > 0, be = !!E.alphaHash, Ne = !!E.extensions;
    let We = 0;
    E.toneMapped && (I === null || I.isXRRenderTarget === !0) && (We = a.toneMapping);
    const Ge = {
      shaderID: K,
      shaderType: E.type,
      shaderName: E.name,
      vertexShader: ie,
      fragmentShader: b,
      defines: E.defines,
      customVertexShaderID: U,
      customFragmentShaderID: G,
      isRawShaderMaterial: E.isRawShaderMaterial === !0,
      glslVersion: E.glslVersion,
      precision: d,
      batching: he,
      batchingColor: he && B._colorsTexture !== null,
      instancing: re,
      instancingColor: re && B.instanceColor !== null,
      instancingMorph: re && B.morphTexture !== null,
      supportsVertexTextures: h,
      outputColorSpace: I === null ? a.outputColorSpace : I.isXRRenderTarget === !0 ? I.texture.colorSpace : pi,
      alphaToCoverage: !!E.alphaToCoverage,
      map: fe,
      matcap: W,
      envMap: ce,
      envMapMode: ce && ne.mapping,
      envMapCubeUVHeight: q,
      aoMap: P,
      lightMap: pe,
      bumpMap: ae,
      normalMap: ve,
      displacementMap: h && te,
      emissiveMap: Te,
      normalMapObjectSpace: ve && E.normalMapType === 1,
      normalMapTangentSpace: ve && E.normalMapType === 0,
      metalnessMap: me,
      roughnessMap: M,
      anisotropy: y,
      anisotropyMap: de,
      clearcoat: H,
      clearcoatMap: xe,
      clearcoatNormalMap: De,
      clearcoatRoughnessMap: ye,
      dispersion: $,
      iridescence: ee,
      iridescenceMap: Re,
      iridescenceThicknessMap: Pe,
      sheen: oe,
      sheenColorMap: Ue,
      sheenRoughnessMap: Me,
      specularMap: ze,
      specularColorMap: Fe,
      specularIntensityMap: je,
      transmission: Se,
      transmissionMap: X,
      thicknessMap: _e,
      gradientMap: se,
      opaque: E.transparent === !1 && E.blending === 1 && E.alphaToCoverage === !1,
      alphaMap: Ee,
      alphaTest: Ae,
      alphaHash: be,
      combine: E.combine,
      //
      mapUv: fe && v(E.map.channel),
      aoMapUv: P && v(E.aoMap.channel),
      lightMapUv: pe && v(E.lightMap.channel),
      bumpMapUv: ae && v(E.bumpMap.channel),
      normalMapUv: ve && v(E.normalMap.channel),
      displacementMapUv: te && v(E.displacementMap.channel),
      emissiveMapUv: Te && v(E.emissiveMap.channel),
      metalnessMapUv: me && v(E.metalnessMap.channel),
      roughnessMapUv: M && v(E.roughnessMap.channel),
      anisotropyMapUv: de && v(E.anisotropyMap.channel),
      clearcoatMapUv: xe && v(E.clearcoatMap.channel),
      clearcoatNormalMapUv: De && v(E.clearcoatNormalMap.channel),
      clearcoatRoughnessMapUv: ye && v(E.clearcoatRoughnessMap.channel),
      iridescenceMapUv: Re && v(E.iridescenceMap.channel),
      iridescenceThicknessMapUv: Pe && v(E.iridescenceThicknessMap.channel),
      sheenColorMapUv: Ue && v(E.sheenColorMap.channel),
      sheenRoughnessMapUv: Me && v(E.sheenRoughnessMap.channel),
      specularMapUv: ze && v(E.specularMap.channel),
      specularColorMapUv: Fe && v(E.specularColorMap.channel),
      specularIntensityMapUv: je && v(E.specularIntensityMap.channel),
      transmissionMapUv: X && v(E.transmissionMap.channel),
      thicknessMapUv: _e && v(E.thicknessMap.channel),
      alphaMapUv: Ee && v(E.alphaMap.channel),
      //
      vertexTangents: !!O.attributes.tangent && (ve || y),
      vertexColors: E.vertexColors,
      vertexAlphas: E.vertexColors === !0 && !!O.attributes.color && O.attributes.color.itemSize === 4,
      pointsUvs: B.isPoints === !0 && !!O.attributes.uv && (fe || Ee),
      fog: !!k,
      useFog: E.fog === !0,
      fogExp2: !!k && k.isFogExp2,
      flatShading: E.flatShading === !0,
      sizeAttenuation: E.sizeAttenuation === !0,
      logarithmicDepthBuffer: f,
      reverseDepthBuffer: V,
      skinning: B.isSkinnedMesh === !0,
      morphTargets: O.morphAttributes.position !== void 0,
      morphNormals: O.morphAttributes.normal !== void 0,
      morphColors: O.morphAttributes.color !== void 0,
      morphTargetsCount: N,
      morphTextureStride: Y,
      numDirLights: S.directional.length,
      numPointLights: S.point.length,
      numSpotLights: S.spot.length,
      numSpotLightMaps: S.spotLightMap.length,
      numRectAreaLights: S.rectArea.length,
      numHemiLights: S.hemi.length,
      numDirLightShadows: S.directionalShadowMap.length,
      numPointLightShadows: S.pointShadowMap.length,
      numSpotLightShadows: S.spotShadowMap.length,
      numSpotLightShadowsWithMaps: S.numSpotLightShadowsWithMaps,
      numLightProbes: S.numLightProbes,
      numClippingPlanes: s.numPlanes,
      numClipIntersection: s.numIntersection,
      dithering: E.dithering,
      shadowMapEnabled: a.shadowMap.enabled && F.length > 0,
      shadowMapType: a.shadowMap.type,
      toneMapping: We,
      decodeVideoTexture: fe && E.map.isVideoTexture === !0 && $e.getTransfer(E.map.colorSpace) === it,
      decodeVideoTextureEmissive: Te && E.emissiveMap.isVideoTexture === !0 && $e.getTransfer(E.emissiveMap.colorSpace) === it,
      premultipliedAlpha: E.premultipliedAlpha,
      doubleSided: E.side === 2,
      flipSided: E.side === 1,
      useDepthPacking: E.depthPacking >= 0,
      depthPacking: E.depthPacking || 0,
      index0AttributeName: E.index0AttributeName,
      extensionClipCullDistance: Ne && E.extensions.clipCullDistance === !0 && r.has("WEBGL_clip_cull_distance"),
      extensionMultiDraw: (Ne && E.extensions.multiDraw === !0 || he) && r.has("WEBGL_multi_draw"),
      rendererExtensionParallelShaderCompile: r.has("KHR_parallel_shader_compile"),
      customProgramCacheKey: E.customProgramCacheKey()
    };
    return Ge.vertexUv1s = c.has(1), Ge.vertexUv2s = c.has(2), Ge.vertexUv3s = c.has(3), c.clear(), Ge;
  }
  function p(E) {
    const S = [];
    if (E.shaderID ? S.push(E.shaderID) : (S.push(E.customVertexShaderID), S.push(E.customFragmentShaderID)), E.defines !== void 0)
      for (const F in E.defines)
        S.push(F), S.push(E.defines[F]);
    return E.isRawShaderMaterial === !1 && (T(S, E), x(S, E), S.push(a.outputColorSpace)), S.push(E.customProgramCacheKey), S.join();
  }
  function T(E, S) {
    E.push(S.precision), E.push(S.outputColorSpace), E.push(S.envMapMode), E.push(S.envMapCubeUVHeight), E.push(S.mapUv), E.push(S.alphaMapUv), E.push(S.lightMapUv), E.push(S.aoMapUv), E.push(S.bumpMapUv), E.push(S.normalMapUv), E.push(S.displacementMapUv), E.push(S.emissiveMapUv), E.push(S.metalnessMapUv), E.push(S.roughnessMapUv), E.push(S.anisotropyMapUv), E.push(S.clearcoatMapUv), E.push(S.clearcoatNormalMapUv), E.push(S.clearcoatRoughnessMapUv), E.push(S.iridescenceMapUv), E.push(S.iridescenceThicknessMapUv), E.push(S.sheenColorMapUv), E.push(S.sheenRoughnessMapUv), E.push(S.specularMapUv), E.push(S.specularColorMapUv), E.push(S.specularIntensityMapUv), E.push(S.transmissionMapUv), E.push(S.thicknessMapUv), E.push(S.combine), E.push(S.fogExp2), E.push(S.sizeAttenuation), E.push(S.morphTargetsCount), E.push(S.morphAttributeCount), E.push(S.numDirLights), E.push(S.numPointLights), E.push(S.numSpotLights), E.push(S.numSpotLightMaps), E.push(S.numHemiLights), E.push(S.numRectAreaLights), E.push(S.numDirLightShadows), E.push(S.numPointLightShadows), E.push(S.numSpotLightShadows), E.push(S.numSpotLightShadowsWithMaps), E.push(S.numLightProbes), E.push(S.shadowMapType), E.push(S.toneMapping), E.push(S.numClippingPlanes), E.push(S.numClipIntersection), E.push(S.depthPacking);
  }
  function x(E, S) {
    o.disableAll(), S.supportsVertexTextures && o.enable(0), S.instancing && o.enable(1), S.instancingColor && o.enable(2), S.instancingMorph && o.enable(3), S.matcap && o.enable(4), S.envMap && o.enable(5), S.normalMapObjectSpace && o.enable(6), S.normalMapTangentSpace && o.enable(7), S.clearcoat && o.enable(8), S.iridescence && o.enable(9), S.alphaTest && o.enable(10), S.vertexColors && o.enable(11), S.vertexAlphas && o.enable(12), S.vertexUv1s && o.enable(13), S.vertexUv2s && o.enable(14), S.vertexUv3s && o.enable(15), S.vertexTangents && o.enable(16), S.anisotropy && o.enable(17), S.alphaHash && o.enable(18), S.batching && o.enable(19), S.dispersion && o.enable(20), S.batchingColor && o.enable(21), E.push(o.mask), o.disableAll(), S.fog && o.enable(0), S.useFog && o.enable(1), S.flatShading && o.enable(2), S.logarithmicDepthBuffer && o.enable(3), S.reverseDepthBuffer && o.enable(4), S.skinning && o.enable(5), S.morphTargets && o.enable(6), S.morphNormals && o.enable(7), S.morphColors && o.enable(8), S.premultipliedAlpha && o.enable(9), S.shadowMapEnabled && o.enable(10), S.doubleSided && o.enable(11), S.flipSided && o.enable(12), S.useDepthPacking && o.enable(13), S.dithering && o.enable(14), S.transmission && o.enable(15), S.sheen && o.enable(16), S.opaque && o.enable(17), S.pointsUvs && o.enable(18), S.decodeVideoTexture && o.enable(19), S.decodeVideoTextureEmissive && o.enable(20), S.alphaToCoverage && o.enable(21), E.push(o.mask);
  }
  function _(E) {
    const S = g[E.type];
    let F;
    if (S) {
      const L = an[S];
      F = Qa.clone(L.uniforms);
    } else
      F = E.uniforms;
    return F;
  }
  function D(E, S) {
    let F;
    for (let L = 0, B = u.length; L < B; L++) {
      const k = u[L];
      if (k.cacheKey === S) {
        F = k, ++F.usedTimes;
        break;
      }
    }
    return F === void 0 && (F = new rd(a, S, E, i), u.push(F)), F;
  }
  function C(E) {
    if (--E.usedTimes === 0) {
      const S = u.indexOf(E);
      u[S] = u[u.length - 1], u.pop(), E.destroy();
    }
  }
  function A(E) {
    l.remove(E);
  }
  function R() {
    l.dispose();
  }
  return {
    getParameters: m,
    getProgramCacheKey: p,
    getUniforms: _,
    acquireProgram: D,
    releaseProgram: C,
    releaseShaderCache: A,
    // Exposed for resource monitoring & error feedback via renderer.info:
    programs: u,
    dispose: R
  };
}
function cd() {
  let a = /* @__PURE__ */ new WeakMap();
  function e(s) {
    return a.has(s);
  }
  function t(s) {
    let o = a.get(s);
    return o === void 0 && (o = {}, a.set(s, o)), o;
  }
  function r(s) {
    a.delete(s);
  }
  function n(s, o, l) {
    a.get(s)[o] = l;
  }
  function i() {
    a = /* @__PURE__ */ new WeakMap();
  }
  return {
    has: e,
    get: t,
    remove: r,
    update: n,
    dispose: i
  };
}
function ud(a, e) {
  return a.groupOrder !== e.groupOrder ? a.groupOrder - e.groupOrder : a.renderOrder !== e.renderOrder ? a.renderOrder - e.renderOrder : a.material.id !== e.material.id ? a.material.id - e.material.id : a.z !== e.z ? a.z - e.z : a.id - e.id;
}
function so(a, e) {
  return a.groupOrder !== e.groupOrder ? a.groupOrder - e.groupOrder : a.renderOrder !== e.renderOrder ? a.renderOrder - e.renderOrder : a.z !== e.z ? e.z - a.z : a.id - e.id;
}
function oo() {
  const a = [];
  let e = 0;
  const t = [], r = [], n = [];
  function i() {
    e = 0, t.length = 0, r.length = 0, n.length = 0;
  }
  function s(f, h, d, g, v, m) {
    let p = a[e];
    return p === void 0 ? (p = {
      id: f.id,
      object: f,
      geometry: h,
      material: d,
      groupOrder: g,
      renderOrder: f.renderOrder,
      z: v,
      group: m
    }, a[e] = p) : (p.id = f.id, p.object = f, p.geometry = h, p.material = d, p.groupOrder = g, p.renderOrder = f.renderOrder, p.z = v, p.group = m), e++, p;
  }
  function o(f, h, d, g, v, m) {
    const p = s(f, h, d, g, v, m);
    d.transmission > 0 ? r.push(p) : d.transparent === !0 ? n.push(p) : t.push(p);
  }
  function l(f, h, d, g, v, m) {
    const p = s(f, h, d, g, v, m);
    d.transmission > 0 ? r.unshift(p) : d.transparent === !0 ? n.unshift(p) : t.unshift(p);
  }
  function c(f, h) {
    t.length > 1 && t.sort(f || ud), r.length > 1 && r.sort(h || so), n.length > 1 && n.sort(h || so);
  }
  function u() {
    for (let f = e, h = a.length; f < h; f++) {
      const d = a[f];
      if (d.id === null) break;
      d.id = null, d.object = null, d.geometry = null, d.material = null, d.group = null;
    }
  }
  return {
    opaque: t,
    transmissive: r,
    transparent: n,
    init: i,
    push: o,
    unshift: l,
    finish: u,
    sort: c
  };
}
function hd() {
  let a = /* @__PURE__ */ new WeakMap();
  function e(r, n) {
    const i = a.get(r);
    let s;
    return i === void 0 ? (s = new oo(), a.set(r, [s])) : n >= i.length ? (s = new oo(), i.push(s)) : s = i[n], s;
  }
  function t() {
    a = /* @__PURE__ */ new WeakMap();
  }
  return {
    get: e,
    dispose: t
  };
}
function fd() {
  const a = {};
  return {
    get: function(e) {
      if (a[e.id] !== void 0)
        return a[e.id];
      let t;
      switch (e.type) {
        case "DirectionalLight":
          t = {
            direction: new j(),
            color: new Ke()
          };
          break;
        case "SpotLight":
          t = {
            position: new j(),
            direction: new j(),
            color: new Ke(),
            distance: 0,
            coneCos: 0,
            penumbraCos: 0,
            decay: 0
          };
          break;
        case "PointLight":
          t = {
            position: new j(),
            color: new Ke(),
            distance: 0,
            decay: 0
          };
          break;
        case "HemisphereLight":
          t = {
            direction: new j(),
            skyColor: new Ke(),
            groundColor: new Ke()
          };
          break;
        case "RectAreaLight":
          t = {
            color: new Ke(),
            position: new j(),
            halfWidth: new j(),
            halfHeight: new j()
          };
          break;
      }
      return a[e.id] = t, t;
    }
  };
}
function dd() {
  const a = {};
  return {
    get: function(e) {
      if (a[e.id] !== void 0)
        return a[e.id];
      let t;
      switch (e.type) {
        case "DirectionalLight":
          t = {
            shadowIntensity: 1,
            shadowBias: 0,
            shadowNormalBias: 0,
            shadowRadius: 1,
            shadowMapSize: new Ce()
          };
          break;
        case "SpotLight":
          t = {
            shadowIntensity: 1,
            shadowBias: 0,
            shadowNormalBias: 0,
            shadowRadius: 1,
            shadowMapSize: new Ce()
          };
          break;
        case "PointLight":
          t = {
            shadowIntensity: 1,
            shadowBias: 0,
            shadowNormalBias: 0,
            shadowRadius: 1,
            shadowMapSize: new Ce(),
            shadowCameraNear: 1,
            shadowCameraFar: 1e3
          };
          break;
      }
      return a[e.id] = t, t;
    }
  };
}
let pd = 0;
function md(a, e) {
  return (e.castShadow ? 2 : 0) - (a.castShadow ? 2 : 0) + (e.map ? 1 : 0) - (a.map ? 1 : 0);
}
function gd(a) {
  const e = new fd(), t = dd(), r = {
    version: 0,
    hash: {
      directionalLength: -1,
      pointLength: -1,
      spotLength: -1,
      rectAreaLength: -1,
      hemiLength: -1,
      numDirectionalShadows: -1,
      numPointShadows: -1,
      numSpotShadows: -1,
      numSpotMaps: -1,
      numLightProbes: -1
    },
    ambient: [0, 0, 0],
    probe: [],
    directional: [],
    directionalShadow: [],
    directionalShadowMap: [],
    directionalShadowMatrix: [],
    spot: [],
    spotLightMap: [],
    spotShadow: [],
    spotShadowMap: [],
    spotLightMatrix: [],
    rectArea: [],
    rectAreaLTC1: null,
    rectAreaLTC2: null,
    point: [],
    pointShadow: [],
    pointShadowMap: [],
    pointShadowMatrix: [],
    hemi: [],
    numSpotLightShadowsWithMaps: 0,
    numLightProbes: 0
  };
  for (let c = 0; c < 9; c++) r.probe.push(new j());
  const n = new j(), i = new st(), s = new st();
  function o(c) {
    let u = 0, f = 0, h = 0;
    for (let E = 0; E < 9; E++) r.probe[E].set(0, 0, 0);
    let d = 0, g = 0, v = 0, m = 0, p = 0, T = 0, x = 0, _ = 0, D = 0, C = 0, A = 0;
    c.sort(md);
    for (let E = 0, S = c.length; E < S; E++) {
      const F = c[E], L = F.color, B = F.intensity, k = F.distance, O = F.shadow && F.shadow.map ? F.shadow.map.texture : null;
      if (F.isAmbientLight)
        u += L.r * B, f += L.g * B, h += L.b * B;
      else if (F.isLightProbe) {
        for (let z = 0; z < 9; z++)
          r.probe[z].addScaledVector(F.sh.coefficients[z], B);
        A++;
      } else if (F.isDirectionalLight) {
        const z = e.get(F);
        if (z.color.copy(F.color).multiplyScalar(F.intensity), F.castShadow) {
          const ne = F.shadow, q = t.get(F);
          q.shadowIntensity = ne.intensity, q.shadowBias = ne.bias, q.shadowNormalBias = ne.normalBias, q.shadowRadius = ne.radius, q.shadowMapSize = ne.mapSize, r.directionalShadow[d] = q, r.directionalShadowMap[d] = O, r.directionalShadowMatrix[d] = F.shadow.matrix, T++;
        }
        r.directional[d] = z, d++;
      } else if (F.isSpotLight) {
        const z = e.get(F);
        z.position.setFromMatrixPosition(F.matrixWorld), z.color.copy(L).multiplyScalar(B), z.distance = k, z.coneCos = Math.cos(F.angle), z.penumbraCos = Math.cos(F.angle * (1 - F.penumbra)), z.decay = F.decay, r.spot[v] = z;
        const ne = F.shadow;
        if (F.map && (r.spotLightMap[D] = F.map, D++, ne.updateMatrices(F), F.castShadow && C++), r.spotLightMatrix[v] = ne.matrix, F.castShadow) {
          const q = t.get(F);
          q.shadowIntensity = ne.intensity, q.shadowBias = ne.bias, q.shadowNormalBias = ne.normalBias, q.shadowRadius = ne.radius, q.shadowMapSize = ne.mapSize, r.spotShadow[v] = q, r.spotShadowMap[v] = O, _++;
        }
        v++;
      } else if (F.isRectAreaLight) {
        const z = e.get(F);
        z.color.copy(L).multiplyScalar(B), z.halfWidth.set(F.width * 0.5, 0, 0), z.halfHeight.set(0, F.height * 0.5, 0), r.rectArea[m] = z, m++;
      } else if (F.isPointLight) {
        const z = e.get(F);
        if (z.color.copy(F.color).multiplyScalar(F.intensity), z.distance = F.distance, z.decay = F.decay, F.castShadow) {
          const ne = F.shadow, q = t.get(F);
          q.shadowIntensity = ne.intensity, q.shadowBias = ne.bias, q.shadowNormalBias = ne.normalBias, q.shadowRadius = ne.radius, q.shadowMapSize = ne.mapSize, q.shadowCameraNear = ne.camera.near, q.shadowCameraFar = ne.camera.far, r.pointShadow[g] = q, r.pointShadowMap[g] = O, r.pointShadowMatrix[g] = F.shadow.matrix, x++;
        }
        r.point[g] = z, g++;
      } else if (F.isHemisphereLight) {
        const z = e.get(F);
        z.skyColor.copy(F.color).multiplyScalar(B), z.groundColor.copy(F.groundColor).multiplyScalar(B), r.hemi[p] = z, p++;
      }
    }
    m > 0 && (a.has("OES_texture_float_linear") === !0 ? (r.rectAreaLTC1 = Le.LTC_FLOAT_1, r.rectAreaLTC2 = Le.LTC_FLOAT_2) : (r.rectAreaLTC1 = Le.LTC_HALF_1, r.rectAreaLTC2 = Le.LTC_HALF_2)), r.ambient[0] = u, r.ambient[1] = f, r.ambient[2] = h;
    const R = r.hash;
    (R.directionalLength !== d || R.pointLength !== g || R.spotLength !== v || R.rectAreaLength !== m || R.hemiLength !== p || R.numDirectionalShadows !== T || R.numPointShadows !== x || R.numSpotShadows !== _ || R.numSpotMaps !== D || R.numLightProbes !== A) && (r.directional.length = d, r.spot.length = v, r.rectArea.length = m, r.point.length = g, r.hemi.length = p, r.directionalShadow.length = T, r.directionalShadowMap.length = T, r.pointShadow.length = x, r.pointShadowMap.length = x, r.spotShadow.length = _, r.spotShadowMap.length = _, r.directionalShadowMatrix.length = T, r.pointShadowMatrix.length = x, r.spotLightMatrix.length = _ + D - C, r.spotLightMap.length = D, r.numSpotLightShadowsWithMaps = C, r.numLightProbes = A, R.directionalLength = d, R.pointLength = g, R.spotLength = v, R.rectAreaLength = m, R.hemiLength = p, R.numDirectionalShadows = T, R.numPointShadows = x, R.numSpotShadows = _, R.numSpotMaps = D, R.numLightProbes = A, r.version = pd++);
  }
  function l(c, u) {
    let f = 0, h = 0, d = 0, g = 0, v = 0;
    const m = u.matrixWorldInverse;
    for (let p = 0, T = c.length; p < T; p++) {
      const x = c[p];
      if (x.isDirectionalLight) {
        const _ = r.directional[f];
        _.direction.setFromMatrixPosition(x.matrixWorld), n.setFromMatrixPosition(x.target.matrixWorld), _.direction.sub(n), _.direction.transformDirection(m), f++;
      } else if (x.isSpotLight) {
        const _ = r.spot[d];
        _.position.setFromMatrixPosition(x.matrixWorld), _.position.applyMatrix4(m), _.direction.setFromMatrixPosition(x.matrixWorld), n.setFromMatrixPosition(x.target.matrixWorld), _.direction.sub(n), _.direction.transformDirection(m), d++;
      } else if (x.isRectAreaLight) {
        const _ = r.rectArea[g];
        _.position.setFromMatrixPosition(x.matrixWorld), _.position.applyMatrix4(m), s.identity(), i.copy(x.matrixWorld), i.premultiply(m), s.extractRotation(i), _.halfWidth.set(x.width * 0.5, 0, 0), _.halfHeight.set(0, x.height * 0.5, 0), _.halfWidth.applyMatrix4(s), _.halfHeight.applyMatrix4(s), g++;
      } else if (x.isPointLight) {
        const _ = r.point[h];
        _.position.setFromMatrixPosition(x.matrixWorld), _.position.applyMatrix4(m), h++;
      } else if (x.isHemisphereLight) {
        const _ = r.hemi[v];
        _.direction.setFromMatrixPosition(x.matrixWorld), _.direction.transformDirection(m), v++;
      }
    }
  }
  return {
    setup: o,
    setupView: l,
    state: r
  };
}
function lo(a) {
  const e = new gd(a), t = [], r = [];
  function n(u) {
    c.camera = u, t.length = 0, r.length = 0;
  }
  function i(u) {
    t.push(u);
  }
  function s(u) {
    r.push(u);
  }
  function o() {
    e.setup(t);
  }
  function l(u) {
    e.setupView(t, u);
  }
  const c = {
    lightsArray: t,
    shadowsArray: r,
    camera: null,
    lights: e,
    transmissionRenderTarget: {}
  };
  return {
    init: n,
    state: c,
    setupLights: o,
    setupLightsView: l,
    pushLight: i,
    pushShadow: s
  };
}
function vd(a) {
  let e = /* @__PURE__ */ new WeakMap();
  function t(n, i = 0) {
    const s = e.get(n);
    let o;
    return s === void 0 ? (o = new lo(a), e.set(n, [o])) : i >= s.length ? (o = new lo(a), s.push(o)) : o = s[i], o;
  }
  function r() {
    e = /* @__PURE__ */ new WeakMap();
  }
  return {
    get: t,
    dispose: r
  };
}
class $o extends vi {
  static get type() {
    return "MeshDepthMaterial";
  }
  constructor(e) {
    super(), this.isMeshDepthMaterial = !0, this.depthPacking = 3200, this.map = null, this.alphaMap = null, this.displacementMap = null, this.displacementScale = 1, this.displacementBias = 0, this.wireframe = !1, this.wireframeLinewidth = 1, this.setValues(e);
  }
  copy(e) {
    return super.copy(e), this.depthPacking = e.depthPacking, this.map = e.map, this.alphaMap = e.alphaMap, this.displacementMap = e.displacementMap, this.displacementScale = e.displacementScale, this.displacementBias = e.displacementBias, this.wireframe = e.wireframe, this.wireframeLinewidth = e.wireframeLinewidth, this;
  }
}
class el extends vi {
  static get type() {
    return "MeshDistanceMaterial";
  }
  constructor(e) {
    super(), this.isMeshDistanceMaterial = !0, this.map = null, this.alphaMap = null, this.displacementMap = null, this.displacementScale = 1, this.displacementBias = 0, this.setValues(e);
  }
  copy(e) {
    return super.copy(e), this.map = e.map, this.alphaMap = e.alphaMap, this.displacementMap = e.displacementMap, this.displacementScale = e.displacementScale, this.displacementBias = e.displacementBias, this;
  }
}
const _d = `void main() {
	gl_Position = vec4( position, 1.0 );
}`, xd = `uniform sampler2D shadow_pass;
uniform vec2 resolution;
uniform float radius;
#include <packing>
void main() {
	const float samples = float( VSM_SAMPLES );
	float mean = 0.0;
	float squared_mean = 0.0;
	float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );
	float uvStart = samples <= 1.0 ? 0.0 : - 1.0;
	for ( float i = 0.0; i < samples; i ++ ) {
		float uvOffset = uvStart + i * uvStride;
		#ifdef HORIZONTAL_PASS
			vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );
			mean += distribution.x;
			squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;
		#else
			float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );
			mean += depth;
			squared_mean += depth * depth;
		#endif
	}
	mean = mean / samples;
	squared_mean = squared_mean / samples;
	float std_dev = sqrt( squared_mean - mean * mean );
	gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );
}`;
function Sd(a, e, t) {
  let r = new Xo();
  const n = new Ce(), i = new Ce(), s = new ot(), o = new $o({ depthPacking: 3201 }), l = new el(), c = {}, u = t.maxTextureSize, f = { 0: 1, 1: 0, 2: 2 }, h = new bn({
    defines: {
      VSM_SAMPLES: 8
    },
    uniforms: {
      shadow_pass: { value: null },
      resolution: { value: new Ce() },
      radius: { value: 4 }
    },
    vertexShader: _d,
    fragmentShader: xd
  }), d = h.clone();
  d.defines.HORIZONTAL_PASS = 1;
  const g = new St();
  g.setAttribute(
    "position",
    new en(
      new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]),
      3
    )
  );
  const v = new Nt(g, h), m = this;
  this.enabled = !1, this.autoUpdate = !0, this.needsUpdate = !1, this.type = 1;
  let p = this.type;
  this.render = function(C, A, R) {
    if (m.enabled === !1 || m.autoUpdate === !1 && m.needsUpdate === !1 || C.length === 0) return;
    const E = a.getRenderTarget(), S = a.getActiveCubeFace(), F = a.getActiveMipmapLevel(), L = a.state;
    L.setBlending(0), L.buffers.color.setClear(1, 1, 1, 1), L.buffers.depth.setTest(!0), L.setScissorTest(!1);
    const B = p !== 3 && this.type === 3, k = p === 3 && this.type !== 3;
    for (let O = 0, z = C.length; O < z; O++) {
      const ne = C[O], q = ne.shadow;
      if (q === void 0) {
        console.warn("THREE.WebGLShadowMap:", ne, "has no shadow.");
        continue;
      }
      if (q.autoUpdate === !1 && q.needsUpdate === !1) continue;
      n.copy(q.mapSize);
      const K = q.getFrameExtents();
      if (n.multiply(K), i.copy(q.mapSize), (n.x > u || n.y > u) && (n.x > u && (i.x = Math.floor(u / K.x), n.x = i.x * K.x, q.mapSize.x = i.x), n.y > u && (i.y = Math.floor(u / K.y), n.y = i.y * K.y, q.mapSize.y = i.y)), q.map === null || B === !0 || k === !0) {
        const N = this.type !== 3 ? { minFilter: 1003, magFilter: 1003 } : {};
        q.map !== null && q.map.dispose(), q.map = new Bn(n.x, n.y, N), q.map.texture.name = ne.name + ".shadowMap", q.camera.updateProjectionMatrix();
      }
      a.setRenderTarget(q.map), a.clear();
      const Z = q.getViewportCount();
      for (let N = 0; N < Z; N++) {
        const Y = q.getViewport(N);
        s.set(
          i.x * Y.x,
          i.y * Y.y,
          i.x * Y.z,
          i.y * Y.w
        ), L.viewport(s), q.updateMatrices(ne, N), r = q.getFrustum(), _(A, R, q.camera, ne, this.type);
      }
      q.isPointLightShadow !== !0 && this.type === 3 && T(q, R), q.needsUpdate = !1;
    }
    p = this.type, m.needsUpdate = !1, a.setRenderTarget(E, S, F);
  };
  function T(C, A) {
    const R = e.update(v);
    h.defines.VSM_SAMPLES !== C.blurSamples && (h.defines.VSM_SAMPLES = C.blurSamples, d.defines.VSM_SAMPLES = C.blurSamples, h.needsUpdate = !0, d.needsUpdate = !0), C.mapPass === null && (C.mapPass = new Bn(n.x, n.y)), h.uniforms.shadow_pass.value = C.map.texture, h.uniforms.resolution.value = C.mapSize, h.uniforms.radius.value = C.radius, a.setRenderTarget(C.mapPass), a.clear(), a.renderBufferDirect(A, null, R, h, v, null), d.uniforms.shadow_pass.value = C.mapPass.texture, d.uniforms.resolution.value = C.mapSize, d.uniforms.radius.value = C.radius, a.setRenderTarget(C.map), a.clear(), a.renderBufferDirect(A, null, R, d, v, null);
  }
  function x(C, A, R, E) {
    let S = null;
    const F = R.isPointLight === !0 ? C.customDistanceMaterial : C.customDepthMaterial;
    if (F !== void 0)
      S = F;
    else if (S = R.isPointLight === !0 ? l : o, a.localClippingEnabled && A.clipShadows === !0 && Array.isArray(A.clippingPlanes) && A.clippingPlanes.length !== 0 || A.displacementMap && A.displacementScale !== 0 || A.alphaMap && A.alphaTest > 0 || A.map && A.alphaTest > 0) {
      const L = S.uuid, B = A.uuid;
      let k = c[L];
      k === void 0 && (k = {}, c[L] = k);
      let O = k[B];
      O === void 0 && (O = S.clone(), k[B] = O, A.addEventListener("dispose", D)), S = O;
    }
    if (S.visible = A.visible, S.wireframe = A.wireframe, E === 3 ? S.side = A.shadowSide !== null ? A.shadowSide : A.side : S.side = A.shadowSide !== null ? A.shadowSide : f[A.side], S.alphaMap = A.alphaMap, S.alphaTest = A.alphaTest, S.map = A.map, S.clipShadows = A.clipShadows, S.clippingPlanes = A.clippingPlanes, S.clipIntersection = A.clipIntersection, S.displacementMap = A.displacementMap, S.displacementScale = A.displacementScale, S.displacementBias = A.displacementBias, S.wireframeLinewidth = A.wireframeLinewidth, S.linewidth = A.linewidth, R.isPointLight === !0 && S.isMeshDistanceMaterial === !0) {
      const L = a.properties.get(S);
      L.light = R;
    }
    return S;
  }
  function _(C, A, R, E, S) {
    if (C.visible === !1) return;
    if (C.layers.test(A.layers) && (C.isMesh || C.isLine || C.isPoints) && (C.castShadow || C.receiveShadow && S === 3) && (!C.frustumCulled || r.intersectsObject(C))) {
      C.modelViewMatrix.multiplyMatrices(R.matrixWorldInverse, C.matrixWorld);
      const B = e.update(C), k = C.material;
      if (Array.isArray(k)) {
        const O = B.groups;
        for (let z = 0, ne = O.length; z < ne; z++) {
          const q = O[z], K = k[q.materialIndex];
          if (K && K.visible) {
            const Z = x(C, K, E, S);
            C.onBeforeShadow(a, C, A, R, B, Z, q), a.renderBufferDirect(R, null, B, Z, C, q), C.onAfterShadow(a, C, A, R, B, Z, q);
          }
        }
      } else if (k.visible) {
        const O = x(C, k, E, S);
        C.onBeforeShadow(a, C, A, R, B, O, null), a.renderBufferDirect(R, null, B, O, C, null), C.onAfterShadow(a, C, A, R, B, O, null);
      }
    }
    const L = C.children;
    for (let B = 0, k = L.length; B < k; B++)
      _(L[B], A, R, E, S);
  }
  function D(C) {
    C.target.removeEventListener("dispose", D);
    for (const R in c) {
      const E = c[R], S = C.target.uuid;
      S in E && (E[S].dispose(), delete E[S]);
    }
  }
}
const yd = {
  0: 1,
  2: 6,
  4: 7,
  3: 5,
  1: 0,
  6: 2,
  7: 4,
  5: 3
};
function Md(a, e) {
  function t() {
    let X = !1;
    const _e = new ot();
    let se = null;
    const Ee = new ot(0, 0, 0, 0);
    return {
      setMask: function(Ae) {
        se !== Ae && !X && (a.colorMask(Ae, Ae, Ae, Ae), se = Ae);
      },
      setLocked: function(Ae) {
        X = Ae;
      },
      setClear: function(Ae, be, Ne, We, Ge) {
        Ge === !0 && (Ae *= We, be *= We, Ne *= We), _e.set(Ae, be, Ne, We), Ee.equals(_e) === !1 && (a.clearColor(Ae, be, Ne, We), Ee.copy(_e));
      },
      reset: function() {
        X = !1, se = null, Ee.set(-1, 0, 0, 0);
      }
    };
  }
  function r() {
    let X = !1, _e = !1, se = null, Ee = null, Ae = null;
    return {
      setReversed: function(be) {
        if (_e !== be) {
          const Ne = e.get("EXT_clip_control");
          _e ? Ne.clipControlEXT(Ne.LOWER_LEFT_EXT, Ne.ZERO_TO_ONE_EXT) : Ne.clipControlEXT(Ne.LOWER_LEFT_EXT, Ne.NEGATIVE_ONE_TO_ONE_EXT);
          const We = Ae;
          Ae = null, this.setClear(We);
        }
        _e = be;
      },
      getReversed: function() {
        return _e;
      },
      setTest: function(be) {
        be ? I(a.DEPTH_TEST) : V(a.DEPTH_TEST);
      },
      setMask: function(be) {
        se !== be && !X && (a.depthMask(be), se = be);
      },
      setFunc: function(be) {
        if (_e && (be = yd[be]), Ee !== be) {
          switch (be) {
            case 0:
              a.depthFunc(a.NEVER);
              break;
            case 1:
              a.depthFunc(a.ALWAYS);
              break;
            case 2:
              a.depthFunc(a.LESS);
              break;
            case 3:
              a.depthFunc(a.LEQUAL);
              break;
            case 4:
              a.depthFunc(a.EQUAL);
              break;
            case 5:
              a.depthFunc(a.GEQUAL);
              break;
            case 6:
              a.depthFunc(a.GREATER);
              break;
            case 7:
              a.depthFunc(a.NOTEQUAL);
              break;
            default:
              a.depthFunc(a.LEQUAL);
          }
          Ee = be;
        }
      },
      setLocked: function(be) {
        X = be;
      },
      setClear: function(be) {
        Ae !== be && (_e && (be = 1 - be), a.clearDepth(be), Ae = be);
      },
      reset: function() {
        X = !1, se = null, Ee = null, Ae = null, _e = !1;
      }
    };
  }
  function n() {
    let X = !1, _e = null, se = null, Ee = null, Ae = null, be = null, Ne = null, We = null, Ge = null;
    return {
      setTest: function(Ve) {
        X || (Ve ? I(a.STENCIL_TEST) : V(a.STENCIL_TEST));
      },
      setMask: function(Ve) {
        _e !== Ve && !X && (a.stencilMask(Ve), _e = Ve);
      },
      setFunc: function(Ve, rt, at) {
        (se !== Ve || Ee !== rt || Ae !== at) && (a.stencilFunc(Ve, rt, at), se = Ve, Ee = rt, Ae = at);
      },
      setOp: function(Ve, rt, at) {
        (be !== Ve || Ne !== rt || We !== at) && (a.stencilOp(Ve, rt, at), be = Ve, Ne = rt, We = at);
      },
      setLocked: function(Ve) {
        X = Ve;
      },
      setClear: function(Ve) {
        Ge !== Ve && (a.clearStencil(Ve), Ge = Ve);
      },
      reset: function() {
        X = !1, _e = null, se = null, Ee = null, Ae = null, be = null, Ne = null, We = null, Ge = null;
      }
    };
  }
  const i = new t(), s = new r(), o = new n(), l = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap();
  let u = {}, f = {}, h = /* @__PURE__ */ new WeakMap(), d = [], g = null, v = !1, m = null, p = null, T = null, x = null, _ = null, D = null, C = null, A = new Ke(0, 0, 0), R = 0, E = !1, S = null, F = null, L = null, B = null, k = null;
  const O = a.getParameter(a.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
  let z = !1, ne = 0;
  const q = a.getParameter(a.VERSION);
  q.indexOf("WebGL") !== -1 ? (ne = parseFloat(/^WebGL (\d)/.exec(q)[1]), z = ne >= 1) : q.indexOf("OpenGL ES") !== -1 && (ne = parseFloat(/^OpenGL ES (\d)/.exec(q)[1]), z = ne >= 2);
  let K = null, Z = {};
  const N = a.getParameter(a.SCISSOR_BOX), Y = a.getParameter(a.VIEWPORT), ie = new ot().fromArray(N), b = new ot().fromArray(Y);
  function U(X, _e, se, Ee) {
    const Ae = new Uint8Array(4), be = a.createTexture();
    a.bindTexture(X, be), a.texParameteri(X, a.TEXTURE_MIN_FILTER, a.NEAREST), a.texParameteri(X, a.TEXTURE_MAG_FILTER, a.NEAREST);
    for (let Ne = 0; Ne < se; Ne++)
      X === a.TEXTURE_3D || X === a.TEXTURE_2D_ARRAY ? a.texImage3D(_e, 0, a.RGBA, 1, 1, Ee, 0, a.RGBA, a.UNSIGNED_BYTE, Ae) : a.texImage2D(_e + Ne, 0, a.RGBA, 1, 1, 0, a.RGBA, a.UNSIGNED_BYTE, Ae);
    return be;
  }
  const G = {};
  G[a.TEXTURE_2D] = U(a.TEXTURE_2D, a.TEXTURE_2D, 1), G[a.TEXTURE_CUBE_MAP] = U(a.TEXTURE_CUBE_MAP, a.TEXTURE_CUBE_MAP_POSITIVE_X, 6), G[a.TEXTURE_2D_ARRAY] = U(a.TEXTURE_2D_ARRAY, a.TEXTURE_2D_ARRAY, 1, 1), G[a.TEXTURE_3D] = U(a.TEXTURE_3D, a.TEXTURE_3D, 1, 1), i.setClear(0, 0, 0, 1), s.setClear(1), o.setClear(0), I(a.DEPTH_TEST), s.setFunc(3), ae(!1), ve(1), I(a.CULL_FACE), P(0);
  function I(X) {
    u[X] !== !0 && (a.enable(X), u[X] = !0);
  }
  function V(X) {
    u[X] !== !1 && (a.disable(X), u[X] = !1);
  }
  function re(X, _e) {
    return f[X] !== _e ? (a.bindFramebuffer(X, _e), f[X] = _e, X === a.DRAW_FRAMEBUFFER && (f[a.FRAMEBUFFER] = _e), X === a.FRAMEBUFFER && (f[a.DRAW_FRAMEBUFFER] = _e), !0) : !1;
  }
  function he(X, _e) {
    let se = d, Ee = !1;
    if (X) {
      se = h.get(_e), se === void 0 && (se = [], h.set(_e, se));
      const Ae = X.textures;
      if (se.length !== Ae.length || se[0] !== a.COLOR_ATTACHMENT0) {
        for (let be = 0, Ne = Ae.length; be < Ne; be++)
          se[be] = a.COLOR_ATTACHMENT0 + be;
        se.length = Ae.length, Ee = !0;
      }
    } else
      se[0] !== a.BACK && (se[0] = a.BACK, Ee = !0);
    Ee && a.drawBuffers(se);
  }
  function fe(X) {
    return g !== X ? (a.useProgram(X), g = X, !0) : !1;
  }
  const W = {
    100: a.FUNC_ADD,
    101: a.FUNC_SUBTRACT,
    102: a.FUNC_REVERSE_SUBTRACT
  };
  W[103] = a.MIN, W[104] = a.MAX;
  const ce = {
    200: a.ZERO,
    201: a.ONE,
    202: a.SRC_COLOR,
    204: a.SRC_ALPHA,
    210: a.SRC_ALPHA_SATURATE,
    208: a.DST_COLOR,
    206: a.DST_ALPHA,
    203: a.ONE_MINUS_SRC_COLOR,
    205: a.ONE_MINUS_SRC_ALPHA,
    209: a.ONE_MINUS_DST_COLOR,
    207: a.ONE_MINUS_DST_ALPHA,
    211: a.CONSTANT_COLOR,
    212: a.ONE_MINUS_CONSTANT_COLOR,
    213: a.CONSTANT_ALPHA,
    214: a.ONE_MINUS_CONSTANT_ALPHA
  };
  function P(X, _e, se, Ee, Ae, be, Ne, We, Ge, Ve) {
    if (X === 0) {
      v === !0 && (V(a.BLEND), v = !1);
      return;
    }
    if (v === !1 && (I(a.BLEND), v = !0), X !== 5) {
      if (X !== m || Ve !== E) {
        if ((p !== 100 || _ !== 100) && (a.blendEquation(a.FUNC_ADD), p = 100, _ = 100), Ve)
          switch (X) {
            case 1:
              a.blendFuncSeparate(a.ONE, a.ONE_MINUS_SRC_ALPHA, a.ONE, a.ONE_MINUS_SRC_ALPHA);
              break;
            case 2:
              a.blendFunc(a.ONE, a.ONE);
              break;
            case 3:
              a.blendFuncSeparate(a.ZERO, a.ONE_MINUS_SRC_COLOR, a.ZERO, a.ONE);
              break;
            case 4:
              a.blendFuncSeparate(a.ZERO, a.SRC_COLOR, a.ZERO, a.SRC_ALPHA);
              break;
            default:
              console.error("THREE.WebGLState: Invalid blending: ", X);
              break;
          }
        else
          switch (X) {
            case 1:
              a.blendFuncSeparate(a.SRC_ALPHA, a.ONE_MINUS_SRC_ALPHA, a.ONE, a.ONE_MINUS_SRC_ALPHA);
              break;
            case 2:
              a.blendFunc(a.SRC_ALPHA, a.ONE);
              break;
            case 3:
              a.blendFuncSeparate(a.ZERO, a.ONE_MINUS_SRC_COLOR, a.ZERO, a.ONE);
              break;
            case 4:
              a.blendFunc(a.ZERO, a.SRC_COLOR);
              break;
            default:
              console.error("THREE.WebGLState: Invalid blending: ", X);
              break;
          }
        T = null, x = null, D = null, C = null, A.set(0, 0, 0), R = 0, m = X, E = Ve;
      }
      return;
    }
    Ae = Ae || _e, be = be || se, Ne = Ne || Ee, (_e !== p || Ae !== _) && (a.blendEquationSeparate(W[_e], W[Ae]), p = _e, _ = Ae), (se !== T || Ee !== x || be !== D || Ne !== C) && (a.blendFuncSeparate(ce[se], ce[Ee], ce[be], ce[Ne]), T = se, x = Ee, D = be, C = Ne), (We.equals(A) === !1 || Ge !== R) && (a.blendColor(We.r, We.g, We.b, Ge), A.copy(We), R = Ge), m = X, E = !1;
  }
  function pe(X, _e) {
    X.side === 2 ? V(a.CULL_FACE) : I(a.CULL_FACE);
    let se = X.side === 1;
    _e && (se = !se), ae(se), X.blending === 1 && X.transparent === !1 ? P(0) : P(X.blending, X.blendEquation, X.blendSrc, X.blendDst, X.blendEquationAlpha, X.blendSrcAlpha, X.blendDstAlpha, X.blendColor, X.blendAlpha, X.premultipliedAlpha), s.setFunc(X.depthFunc), s.setTest(X.depthTest), s.setMask(X.depthWrite), i.setMask(X.colorWrite);
    const Ee = X.stencilWrite;
    o.setTest(Ee), Ee && (o.setMask(X.stencilWriteMask), o.setFunc(X.stencilFunc, X.stencilRef, X.stencilFuncMask), o.setOp(X.stencilFail, X.stencilZFail, X.stencilZPass)), Te(X.polygonOffset, X.polygonOffsetFactor, X.polygonOffsetUnits), X.alphaToCoverage === !0 ? I(a.SAMPLE_ALPHA_TO_COVERAGE) : V(a.SAMPLE_ALPHA_TO_COVERAGE);
  }
  function ae(X) {
    S !== X && (X ? a.frontFace(a.CW) : a.frontFace(a.CCW), S = X);
  }
  function ve(X) {
    X !== 0 ? (I(a.CULL_FACE), X !== F && (X === 1 ? a.cullFace(a.BACK) : X === 2 ? a.cullFace(a.FRONT) : a.cullFace(a.FRONT_AND_BACK))) : V(a.CULL_FACE), F = X;
  }
  function te(X) {
    X !== L && (z && a.lineWidth(X), L = X);
  }
  function Te(X, _e, se) {
    X ? (I(a.POLYGON_OFFSET_FILL), (B !== _e || k !== se) && (a.polygonOffset(_e, se), B = _e, k = se)) : V(a.POLYGON_OFFSET_FILL);
  }
  function me(X) {
    X ? I(a.SCISSOR_TEST) : V(a.SCISSOR_TEST);
  }
  function M(X) {
    X === void 0 && (X = a.TEXTURE0 + O - 1), K !== X && (a.activeTexture(X), K = X);
  }
  function y(X, _e, se) {
    se === void 0 && (K === null ? se = a.TEXTURE0 + O - 1 : se = K);
    let Ee = Z[se];
    Ee === void 0 && (Ee = { type: void 0, texture: void 0 }, Z[se] = Ee), (Ee.type !== X || Ee.texture !== _e) && (K !== se && (a.activeTexture(se), K = se), a.bindTexture(X, _e || G[X]), Ee.type = X, Ee.texture = _e);
  }
  function H() {
    const X = Z[K];
    X !== void 0 && X.type !== void 0 && (a.bindTexture(X.type, null), X.type = void 0, X.texture = void 0);
  }
  function $() {
    try {
      a.compressedTexImage2D.apply(a, arguments);
    } catch (X) {
      console.error("THREE.WebGLState:", X);
    }
  }
  function ee() {
    try {
      a.compressedTexImage3D.apply(a, arguments);
    } catch (X) {
      console.error("THREE.WebGLState:", X);
    }
  }
  function oe() {
    try {
      a.texSubImage2D.apply(a, arguments);
    } catch (X) {
      console.error("THREE.WebGLState:", X);
    }
  }
  function Se() {
    try {
      a.texSubImage3D.apply(a, arguments);
    } catch (X) {
      console.error("THREE.WebGLState:", X);
    }
  }
  function de() {
    try {
      a.compressedTexSubImage2D.apply(a, arguments);
    } catch (X) {
      console.error("THREE.WebGLState:", X);
    }
  }
  function xe() {
    try {
      a.compressedTexSubImage3D.apply(a, arguments);
    } catch (X) {
      console.error("THREE.WebGLState:", X);
    }
  }
  function De() {
    try {
      a.texStorage2D.apply(a, arguments);
    } catch (X) {
      console.error("THREE.WebGLState:", X);
    }
  }
  function ye() {
    try {
      a.texStorage3D.apply(a, arguments);
    } catch (X) {
      console.error("THREE.WebGLState:", X);
    }
  }
  function Re() {
    try {
      a.texImage2D.apply(a, arguments);
    } catch (X) {
      console.error("THREE.WebGLState:", X);
    }
  }
  function Pe() {
    try {
      a.texImage3D.apply(a, arguments);
    } catch (X) {
      console.error("THREE.WebGLState:", X);
    }
  }
  function Ue(X) {
    ie.equals(X) === !1 && (a.scissor(X.x, X.y, X.z, X.w), ie.copy(X));
  }
  function Me(X) {
    b.equals(X) === !1 && (a.viewport(X.x, X.y, X.z, X.w), b.copy(X));
  }
  function ze(X, _e) {
    let se = c.get(_e);
    se === void 0 && (se = /* @__PURE__ */ new WeakMap(), c.set(_e, se));
    let Ee = se.get(X);
    Ee === void 0 && (Ee = a.getUniformBlockIndex(_e, X.name), se.set(X, Ee));
  }
  function Fe(X, _e) {
    const Ee = c.get(_e).get(X);
    l.get(_e) !== Ee && (a.uniformBlockBinding(_e, Ee, X.__bindingPointIndex), l.set(_e, Ee));
  }
  function je() {
    a.disable(a.BLEND), a.disable(a.CULL_FACE), a.disable(a.DEPTH_TEST), a.disable(a.POLYGON_OFFSET_FILL), a.disable(a.SCISSOR_TEST), a.disable(a.STENCIL_TEST), a.disable(a.SAMPLE_ALPHA_TO_COVERAGE), a.blendEquation(a.FUNC_ADD), a.blendFunc(a.ONE, a.ZERO), a.blendFuncSeparate(a.ONE, a.ZERO, a.ONE, a.ZERO), a.blendColor(0, 0, 0, 0), a.colorMask(!0, !0, !0, !0), a.clearColor(0, 0, 0, 0), a.depthMask(!0), a.depthFunc(a.LESS), s.setReversed(!1), a.clearDepth(1), a.stencilMask(4294967295), a.stencilFunc(a.ALWAYS, 0, 4294967295), a.stencilOp(a.KEEP, a.KEEP, a.KEEP), a.clearStencil(0), a.cullFace(a.BACK), a.frontFace(a.CCW), a.polygonOffset(0, 0), a.activeTexture(a.TEXTURE0), a.bindFramebuffer(a.FRAMEBUFFER, null), a.bindFramebuffer(a.DRAW_FRAMEBUFFER, null), a.bindFramebuffer(a.READ_FRAMEBUFFER, null), a.useProgram(null), a.lineWidth(1), a.scissor(0, 0, a.canvas.width, a.canvas.height), a.viewport(0, 0, a.canvas.width, a.canvas.height), u = {}, K = null, Z = {}, f = {}, h = /* @__PURE__ */ new WeakMap(), d = [], g = null, v = !1, m = null, p = null, T = null, x = null, _ = null, D = null, C = null, A = new Ke(0, 0, 0), R = 0, E = !1, S = null, F = null, L = null, B = null, k = null, ie.set(0, 0, a.canvas.width, a.canvas.height), b.set(0, 0, a.canvas.width, a.canvas.height), i.reset(), s.reset(), o.reset();
  }
  return {
    buffers: {
      color: i,
      depth: s,
      stencil: o
    },
    enable: I,
    disable: V,
    bindFramebuffer: re,
    drawBuffers: he,
    useProgram: fe,
    setBlending: P,
    setMaterial: pe,
    setFlipSided: ae,
    setCullFace: ve,
    setLineWidth: te,
    setPolygonOffset: Te,
    setScissorTest: me,
    activeTexture: M,
    bindTexture: y,
    unbindTexture: H,
    compressedTexImage2D: $,
    compressedTexImage3D: ee,
    texImage2D: Re,
    texImage3D: Pe,
    updateUBOMapping: ze,
    uniformBlockBinding: Fe,
    texStorage2D: De,
    texStorage3D: ye,
    texSubImage2D: oe,
    texSubImage3D: Se,
    compressedTexSubImage2D: de,
    compressedTexSubImage3D: xe,
    scissor: Ue,
    viewport: Me,
    reset: je
  };
}
function co(a, e, t, r) {
  const n = Ed(r);
  switch (t) {
    case 1021:
      return a * e;
    case 1024:
      return a * e;
    case 1025:
      return a * e * 2;
    case 1028:
      return a * e / n.components * n.byteLength;
    case 1029:
      return a * e / n.components * n.byteLength;
    case 1030:
      return a * e * 2 / n.components * n.byteLength;
    case 1031:
      return a * e * 2 / n.components * n.byteLength;
    case 1022:
      return a * e * 3 / n.components * n.byteLength;
    case 1023:
      return a * e * 4 / n.components * n.byteLength;
    case 1033:
      return a * e * 4 / n.components * n.byteLength;
    case 33776:
    case 33777:
      return Math.floor((a + 3) / 4) * Math.floor((e + 3) / 4) * 8;
    case 33778:
    case 33779:
      return Math.floor((a + 3) / 4) * Math.floor((e + 3) / 4) * 16;
    case 35841:
    case 35843:
      return Math.max(a, 16) * Math.max(e, 8) / 4;
    case 35840:
    case 35842:
      return Math.max(a, 8) * Math.max(e, 8) / 2;
    case 36196:
    case 37492:
      return Math.floor((a + 3) / 4) * Math.floor((e + 3) / 4) * 8;
    case 37496:
      return Math.floor((a + 3) / 4) * Math.floor((e + 3) / 4) * 16;
    case 37808:
      return Math.floor((a + 3) / 4) * Math.floor((e + 3) / 4) * 16;
    case 37809:
      return Math.floor((a + 4) / 5) * Math.floor((e + 3) / 4) * 16;
    case 37810:
      return Math.floor((a + 4) / 5) * Math.floor((e + 4) / 5) * 16;
    case 37811:
      return Math.floor((a + 5) / 6) * Math.floor((e + 4) / 5) * 16;
    case 37812:
      return Math.floor((a + 5) / 6) * Math.floor((e + 5) / 6) * 16;
    case 37813:
      return Math.floor((a + 7) / 8) * Math.floor((e + 4) / 5) * 16;
    case 37814:
      return Math.floor((a + 7) / 8) * Math.floor((e + 5) / 6) * 16;
    case 37815:
      return Math.floor((a + 7) / 8) * Math.floor((e + 7) / 8) * 16;
    case 37816:
      return Math.floor((a + 9) / 10) * Math.floor((e + 4) / 5) * 16;
    case 37817:
      return Math.floor((a + 9) / 10) * Math.floor((e + 5) / 6) * 16;
    case 37818:
      return Math.floor((a + 9) / 10) * Math.floor((e + 7) / 8) * 16;
    case 37819:
      return Math.floor((a + 9) / 10) * Math.floor((e + 9) / 10) * 16;
    case 37820:
      return Math.floor((a + 11) / 12) * Math.floor((e + 9) / 10) * 16;
    case 37821:
      return Math.floor((a + 11) / 12) * Math.floor((e + 11) / 12) * 16;
    case 36492:
    case 36494:
    case 36495:
      return Math.ceil(a / 4) * Math.ceil(e / 4) * 16;
    case 36283:
    case 36284:
      return Math.ceil(a / 4) * Math.ceil(e / 4) * 8;
    case 36285:
    case 36286:
      return Math.ceil(a / 4) * Math.ceil(e / 4) * 16;
  }
  throw new Error(
    `Unable to determine texture byte length for ${t} format.`
  );
}
function Ed(a) {
  switch (a) {
    case 1009:
    case 1010:
      return { byteLength: 1, components: 1 };
    case 1012:
    case 1011:
    case 1016:
      return { byteLength: 2, components: 1 };
    case 1017:
    case 1018:
      return { byteLength: 2, components: 4 };
    case 1014:
    case 1013:
    case 1015:
      return { byteLength: 4, components: 1 };
    case 35902:
      return { byteLength: 4, components: 3 };
  }
  throw new Error(`Unknown texture type ${a}.`);
}
function Td(a, e, t, r, n, i, s) {
  const o = e.has("WEBGL_multisampled_render_to_texture") ? e.get("WEBGL_multisampled_render_to_texture") : null, l = typeof navigator > "u" ? !1 : /OculusBrowser/g.test(navigator.userAgent), c = new Ce(), u = /* @__PURE__ */ new WeakMap();
  let f;
  const h = /* @__PURE__ */ new WeakMap();
  let d = !1;
  try {
    d = typeof OffscreenCanvas < "u" && new OffscreenCanvas(1, 1).getContext("2d") !== null;
  } catch {
  }
  function g(M, y) {
    return d ? (
      // eslint-disable-next-line compat/compat
      new OffscreenCanvas(M, y)
    ) : Nr("canvas");
  }
  function v(M, y, H) {
    let $ = 1;
    const ee = me(M);
    if ((ee.width > H || ee.height > H) && ($ = H / Math.max(ee.width, ee.height)), $ < 1)
      if (typeof HTMLImageElement < "u" && M instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && M instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && M instanceof ImageBitmap || typeof VideoFrame < "u" && M instanceof VideoFrame) {
        const oe = Math.floor($ * ee.width), Se = Math.floor($ * ee.height);
        f === void 0 && (f = g(oe, Se));
        const de = y ? g(oe, Se) : f;
        return de.width = oe, de.height = Se, de.getContext("2d").drawImage(M, 0, 0, oe, Se), console.warn("THREE.WebGLRenderer: Texture has been resized from (" + ee.width + "x" + ee.height + ") to (" + oe + "x" + Se + ")."), de;
      } else
        return "data" in M && console.warn("THREE.WebGLRenderer: Image in DataTexture is too big (" + ee.width + "x" + ee.height + ")."), M;
    return M;
  }
  function m(M) {
    return M.generateMipmaps;
  }
  function p(M) {
    a.generateMipmap(M);
  }
  function T(M) {
    return M.isWebGLCubeRenderTarget ? a.TEXTURE_CUBE_MAP : M.isWebGL3DRenderTarget ? a.TEXTURE_3D : M.isWebGLArrayRenderTarget || M.isCompressedArrayTexture ? a.TEXTURE_2D_ARRAY : a.TEXTURE_2D;
  }
  function x(M, y, H, $, ee = !1) {
    if (M !== null) {
      if (a[M] !== void 0) return a[M];
      console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '" + M + "'");
    }
    let oe = y;
    if (y === a.RED && (H === a.FLOAT && (oe = a.R32F), H === a.HALF_FLOAT && (oe = a.R16F), H === a.UNSIGNED_BYTE && (oe = a.R8)), y === a.RED_INTEGER && (H === a.UNSIGNED_BYTE && (oe = a.R8UI), H === a.UNSIGNED_SHORT && (oe = a.R16UI), H === a.UNSIGNED_INT && (oe = a.R32UI), H === a.BYTE && (oe = a.R8I), H === a.SHORT && (oe = a.R16I), H === a.INT && (oe = a.R32I)), y === a.RG && (H === a.FLOAT && (oe = a.RG32F), H === a.HALF_FLOAT && (oe = a.RG16F), H === a.UNSIGNED_BYTE && (oe = a.RG8)), y === a.RG_INTEGER && (H === a.UNSIGNED_BYTE && (oe = a.RG8UI), H === a.UNSIGNED_SHORT && (oe = a.RG16UI), H === a.UNSIGNED_INT && (oe = a.RG32UI), H === a.BYTE && (oe = a.RG8I), H === a.SHORT && (oe = a.RG16I), H === a.INT && (oe = a.RG32I)), y === a.RGB_INTEGER && (H === a.UNSIGNED_BYTE && (oe = a.RGB8UI), H === a.UNSIGNED_SHORT && (oe = a.RGB16UI), H === a.UNSIGNED_INT && (oe = a.RGB32UI), H === a.BYTE && (oe = a.RGB8I), H === a.SHORT && (oe = a.RGB16I), H === a.INT && (oe = a.RGB32I)), y === a.RGBA_INTEGER && (H === a.UNSIGNED_BYTE && (oe = a.RGBA8UI), H === a.UNSIGNED_SHORT && (oe = a.RGBA16UI), H === a.UNSIGNED_INT && (oe = a.RGBA32UI), H === a.BYTE && (oe = a.RGBA8I), H === a.SHORT && (oe = a.RGBA16I), H === a.INT && (oe = a.RGBA32I)), y === a.RGB && H === a.UNSIGNED_INT_5_9_9_9_REV && (oe = a.RGB9_E5), y === a.RGBA) {
      const Se = ee ? kr : $e.getTransfer($);
      H === a.FLOAT && (oe = a.RGBA32F), H === a.HALF_FLOAT && (oe = a.RGBA16F), H === a.UNSIGNED_BYTE && (oe = Se === it ? a.SRGB8_ALPHA8 : a.RGBA8), H === a.UNSIGNED_SHORT_4_4_4_4 && (oe = a.RGBA4), H === a.UNSIGNED_SHORT_5_5_5_1 && (oe = a.RGB5_A1);
    }
    return (oe === a.R16F || oe === a.R32F || oe === a.RG16F || oe === a.RG32F || oe === a.RGBA16F || oe === a.RGBA32F) && e.get("EXT_color_buffer_float"), oe;
  }
  function _(M, y) {
    let H;
    return M ? y === null || y === 1014 || y === 1020 ? H = a.DEPTH24_STENCIL8 : y === 1015 ? H = a.DEPTH32F_STENCIL8 : y === 1012 && (H = a.DEPTH24_STENCIL8, console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")) : y === null || y === 1014 || y === 1020 ? H = a.DEPTH_COMPONENT24 : y === 1015 ? H = a.DEPTH_COMPONENT32F : y === 1012 && (H = a.DEPTH_COMPONENT16), H;
  }
  function D(M, y) {
    return m(M) === !0 || M.isFramebufferTexture && M.minFilter !== 1003 && M.minFilter !== 1006 ? Math.log2(Math.max(y.width, y.height)) + 1 : M.mipmaps !== void 0 && M.mipmaps.length > 0 ? M.mipmaps.length : M.isCompressedTexture && Array.isArray(M.image) ? y.mipmaps.length : 1;
  }
  function C(M) {
    const y = M.target;
    y.removeEventListener("dispose", C), R(y), y.isVideoTexture && u.delete(y);
  }
  function A(M) {
    const y = M.target;
    y.removeEventListener("dispose", A), S(y);
  }
  function R(M) {
    const y = r.get(M);
    if (y.__webglInit === void 0) return;
    const H = M.source, $ = h.get(H);
    if ($) {
      const ee = $[y.__cacheKey];
      ee.usedTimes--, ee.usedTimes === 0 && E(M), Object.keys($).length === 0 && h.delete(H);
    }
    r.remove(M);
  }
  function E(M) {
    const y = r.get(M);
    a.deleteTexture(y.__webglTexture);
    const H = M.source, $ = h.get(H);
    delete $[y.__cacheKey], s.memory.textures--;
  }
  function S(M) {
    const y = r.get(M);
    if (M.depthTexture && (M.depthTexture.dispose(), r.remove(M.depthTexture)), M.isWebGLCubeRenderTarget)
      for (let $ = 0; $ < 6; $++) {
        if (Array.isArray(y.__webglFramebuffer[$]))
          for (let ee = 0; ee < y.__webglFramebuffer[$].length; ee++) a.deleteFramebuffer(y.__webglFramebuffer[$][ee]);
        else
          a.deleteFramebuffer(y.__webglFramebuffer[$]);
        y.__webglDepthbuffer && a.deleteRenderbuffer(y.__webglDepthbuffer[$]);
      }
    else {
      if (Array.isArray(y.__webglFramebuffer))
        for (let $ = 0; $ < y.__webglFramebuffer.length; $++) a.deleteFramebuffer(y.__webglFramebuffer[$]);
      else
        a.deleteFramebuffer(y.__webglFramebuffer);
      if (y.__webglDepthbuffer && a.deleteRenderbuffer(y.__webglDepthbuffer), y.__webglMultisampledFramebuffer && a.deleteFramebuffer(y.__webglMultisampledFramebuffer), y.__webglColorRenderbuffer)
        for (let $ = 0; $ < y.__webglColorRenderbuffer.length; $++)
          y.__webglColorRenderbuffer[$] && a.deleteRenderbuffer(y.__webglColorRenderbuffer[$]);
      y.__webglDepthRenderbuffer && a.deleteRenderbuffer(y.__webglDepthRenderbuffer);
    }
    const H = M.textures;
    for (let $ = 0, ee = H.length; $ < ee; $++) {
      const oe = r.get(H[$]);
      oe.__webglTexture && (a.deleteTexture(oe.__webglTexture), s.memory.textures--), r.remove(H[$]);
    }
    r.remove(M);
  }
  let F = 0;
  function L() {
    F = 0;
  }
  function B() {
    const M = F;
    return M >= n.maxTextures && console.warn("THREE.WebGLTextures: Trying to use " + M + " texture units while this GPU supports only " + n.maxTextures), F += 1, M;
  }
  function k(M) {
    const y = [];
    return y.push(M.wrapS), y.push(M.wrapT), y.push(M.wrapR || 0), y.push(M.magFilter), y.push(M.minFilter), y.push(M.anisotropy), y.push(M.internalFormat), y.push(M.format), y.push(M.type), y.push(M.generateMipmaps), y.push(M.premultiplyAlpha), y.push(M.flipY), y.push(M.unpackAlignment), y.push(M.colorSpace), y.join();
  }
  function O(M, y) {
    const H = r.get(M);
    if (M.isVideoTexture && te(M), M.isRenderTargetTexture === !1 && M.version > 0 && H.__version !== M.version) {
      const $ = M.image;
      if ($ === null)
        console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");
      else if ($.complete === !1)
        console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete");
      else {
        b(H, M, y);
        return;
      }
    }
    t.bindTexture(a.TEXTURE_2D, H.__webglTexture, a.TEXTURE0 + y);
  }
  function z(M, y) {
    const H = r.get(M);
    if (M.version > 0 && H.__version !== M.version) {
      b(H, M, y);
      return;
    }
    t.bindTexture(a.TEXTURE_2D_ARRAY, H.__webglTexture, a.TEXTURE0 + y);
  }
  function ne(M, y) {
    const H = r.get(M);
    if (M.version > 0 && H.__version !== M.version) {
      b(H, M, y);
      return;
    }
    t.bindTexture(a.TEXTURE_3D, H.__webglTexture, a.TEXTURE0 + y);
  }
  function q(M, y) {
    const H = r.get(M);
    if (M.version > 0 && H.__version !== M.version) {
      U(H, M, y);
      return;
    }
    t.bindTexture(a.TEXTURE_CUBE_MAP, H.__webglTexture, a.TEXTURE0 + y);
  }
  const K = {
    1e3: a.REPEAT,
    1001: a.CLAMP_TO_EDGE,
    1002: a.MIRRORED_REPEAT
  }, Z = {
    1003: a.NEAREST,
    1004: a.NEAREST_MIPMAP_NEAREST,
    1005: a.NEAREST_MIPMAP_LINEAR,
    1006: a.LINEAR,
    1007: a.LINEAR_MIPMAP_NEAREST,
    1008: a.LINEAR_MIPMAP_LINEAR
  }, N = {
    512: a.NEVER,
    519: a.ALWAYS,
    513: a.LESS,
    515: a.LEQUAL,
    514: a.EQUAL,
    518: a.GEQUAL,
    516: a.GREATER,
    517: a.NOTEQUAL
  };
  function Y(M, y) {
    if (y.type === 1015 && e.has("OES_texture_float_linear") === !1 && (y.magFilter === 1006 || y.magFilter === 1007 || y.magFilter === 1005 || y.magFilter === 1008 || y.minFilter === 1006 || y.minFilter === 1007 || y.minFilter === 1005 || y.minFilter === 1008) && console.warn("THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."), a.texParameteri(M, a.TEXTURE_WRAP_S, K[y.wrapS]), a.texParameteri(M, a.TEXTURE_WRAP_T, K[y.wrapT]), (M === a.TEXTURE_3D || M === a.TEXTURE_2D_ARRAY) && a.texParameteri(M, a.TEXTURE_WRAP_R, K[y.wrapR]), a.texParameteri(M, a.TEXTURE_MAG_FILTER, Z[y.magFilter]), a.texParameteri(M, a.TEXTURE_MIN_FILTER, Z[y.minFilter]), y.compareFunction && (a.texParameteri(M, a.TEXTURE_COMPARE_MODE, a.COMPARE_REF_TO_TEXTURE), a.texParameteri(M, a.TEXTURE_COMPARE_FUNC, N[y.compareFunction])), e.has("EXT_texture_filter_anisotropic") === !0) {
      if (y.magFilter === 1003 || y.minFilter !== 1005 && y.minFilter !== 1008 || y.type === 1015 && e.has("OES_texture_float_linear") === !1) return;
      if (y.anisotropy > 1 || r.get(y).__currentAnisotropy) {
        const H = e.get("EXT_texture_filter_anisotropic");
        a.texParameterf(M, H.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(y.anisotropy, n.getMaxAnisotropy())), r.get(y).__currentAnisotropy = y.anisotropy;
      }
    }
  }
  function ie(M, y) {
    let H = !1;
    M.__webglInit === void 0 && (M.__webglInit = !0, y.addEventListener("dispose", C));
    const $ = y.source;
    let ee = h.get($);
    ee === void 0 && (ee = {}, h.set($, ee));
    const oe = k(y);
    if (oe !== M.__cacheKey) {
      ee[oe] === void 0 && (ee[oe] = {
        texture: a.createTexture(),
        usedTimes: 0
      }, s.memory.textures++, H = !0), ee[oe].usedTimes++;
      const Se = ee[M.__cacheKey];
      Se !== void 0 && (ee[M.__cacheKey].usedTimes--, Se.usedTimes === 0 && E(y)), M.__cacheKey = oe, M.__webglTexture = ee[oe].texture;
    }
    return H;
  }
  function b(M, y, H) {
    let $ = a.TEXTURE_2D;
    (y.isDataArrayTexture || y.isCompressedArrayTexture) && ($ = a.TEXTURE_2D_ARRAY), y.isData3DTexture && ($ = a.TEXTURE_3D);
    const ee = ie(M, y), oe = y.source;
    t.bindTexture($, M.__webglTexture, a.TEXTURE0 + H);
    const Se = r.get(oe);
    if (oe.version !== Se.__version || ee === !0) {
      t.activeTexture(a.TEXTURE0 + H);
      const de = $e.getPrimaries($e.workingColorSpace), xe = y.colorSpace === Tn ? null : $e.getPrimaries(y.colorSpace), De = y.colorSpace === Tn || de === xe ? a.NONE : a.BROWSER_DEFAULT_WEBGL;
      a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL, y.flipY), a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL, y.premultiplyAlpha), a.pixelStorei(a.UNPACK_ALIGNMENT, y.unpackAlignment), a.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL, De);
      let ye = v(y.image, !1, n.maxTextureSize);
      ye = Te(y, ye);
      const Re = i.convert(y.format, y.colorSpace), Pe = i.convert(y.type);
      let Ue = x(y.internalFormat, Re, Pe, y.colorSpace, y.isVideoTexture);
      Y($, y);
      let Me;
      const ze = y.mipmaps, Fe = y.isVideoTexture !== !0, je = Se.__version === void 0 || ee === !0, X = oe.dataReady, _e = D(y, ye);
      if (y.isDepthTexture)
        Ue = _(y.format === 1027, y.type), je && (Fe ? t.texStorage2D(a.TEXTURE_2D, 1, Ue, ye.width, ye.height) : t.texImage2D(a.TEXTURE_2D, 0, Ue, ye.width, ye.height, 0, Re, Pe, null));
      else if (y.isDataTexture)
        if (ze.length > 0) {
          Fe && je && t.texStorage2D(a.TEXTURE_2D, _e, Ue, ze[0].width, ze[0].height);
          for (let se = 0, Ee = ze.length; se < Ee; se++)
            Me = ze[se], Fe ? X && t.texSubImage2D(a.TEXTURE_2D, se, 0, 0, Me.width, Me.height, Re, Pe, Me.data) : t.texImage2D(a.TEXTURE_2D, se, Ue, Me.width, Me.height, 0, Re, Pe, Me.data);
          y.generateMipmaps = !1;
        } else
          Fe ? (je && t.texStorage2D(a.TEXTURE_2D, _e, Ue, ye.width, ye.height), X && t.texSubImage2D(a.TEXTURE_2D, 0, 0, 0, ye.width, ye.height, Re, Pe, ye.data)) : t.texImage2D(a.TEXTURE_2D, 0, Ue, ye.width, ye.height, 0, Re, Pe, ye.data);
      else if (y.isCompressedTexture)
        if (y.isCompressedArrayTexture) {
          Fe && je && t.texStorage3D(a.TEXTURE_2D_ARRAY, _e, Ue, ze[0].width, ze[0].height, ye.depth);
          for (let se = 0, Ee = ze.length; se < Ee; se++)
            if (Me = ze[se], y.format !== 1023)
              if (Re !== null)
                if (Fe) {
                  if (X)
                    if (y.layerUpdates.size > 0) {
                      const Ae = co(Me.width, Me.height, y.format, y.type);
                      for (const be of y.layerUpdates) {
                        const Ne = Me.data.subarray(
                          be * Ae / Me.data.BYTES_PER_ELEMENT,
                          (be + 1) * Ae / Me.data.BYTES_PER_ELEMENT
                        );
                        t.compressedTexSubImage3D(a.TEXTURE_2D_ARRAY, se, 0, 0, be, Me.width, Me.height, 1, Re, Ne);
                      }
                      y.clearLayerUpdates();
                    } else
                      t.compressedTexSubImage3D(a.TEXTURE_2D_ARRAY, se, 0, 0, 0, Me.width, Me.height, ye.depth, Re, Me.data);
                } else
                  t.compressedTexImage3D(a.TEXTURE_2D_ARRAY, se, Ue, Me.width, Me.height, ye.depth, 0, Me.data, 0, 0);
              else
                console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");
            else
              Fe ? X && t.texSubImage3D(a.TEXTURE_2D_ARRAY, se, 0, 0, 0, Me.width, Me.height, ye.depth, Re, Pe, Me.data) : t.texImage3D(a.TEXTURE_2D_ARRAY, se, Ue, Me.width, Me.height, ye.depth, 0, Re, Pe, Me.data);
        } else {
          Fe && je && t.texStorage2D(a.TEXTURE_2D, _e, Ue, ze[0].width, ze[0].height);
          for (let se = 0, Ee = ze.length; se < Ee; se++)
            Me = ze[se], y.format !== 1023 ? Re !== null ? Fe ? X && t.compressedTexSubImage2D(a.TEXTURE_2D, se, 0, 0, Me.width, Me.height, Re, Me.data) : t.compressedTexImage2D(a.TEXTURE_2D, se, Ue, Me.width, Me.height, 0, Me.data) : console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()") : Fe ? X && t.texSubImage2D(a.TEXTURE_2D, se, 0, 0, Me.width, Me.height, Re, Pe, Me.data) : t.texImage2D(a.TEXTURE_2D, se, Ue, Me.width, Me.height, 0, Re, Pe, Me.data);
        }
      else if (y.isDataArrayTexture)
        if (Fe) {
          if (je && t.texStorage3D(a.TEXTURE_2D_ARRAY, _e, Ue, ye.width, ye.height, ye.depth), X)
            if (y.layerUpdates.size > 0) {
              const se = co(ye.width, ye.height, y.format, y.type);
              for (const Ee of y.layerUpdates) {
                const Ae = ye.data.subarray(
                  Ee * se / ye.data.BYTES_PER_ELEMENT,
                  (Ee + 1) * se / ye.data.BYTES_PER_ELEMENT
                );
                t.texSubImage3D(a.TEXTURE_2D_ARRAY, 0, 0, 0, Ee, ye.width, ye.height, 1, Re, Pe, Ae);
              }
              y.clearLayerUpdates();
            } else
              t.texSubImage3D(a.TEXTURE_2D_ARRAY, 0, 0, 0, 0, ye.width, ye.height, ye.depth, Re, Pe, ye.data);
        } else
          t.texImage3D(a.TEXTURE_2D_ARRAY, 0, Ue, ye.width, ye.height, ye.depth, 0, Re, Pe, ye.data);
      else if (y.isData3DTexture)
        Fe ? (je && t.texStorage3D(a.TEXTURE_3D, _e, Ue, ye.width, ye.height, ye.depth), X && t.texSubImage3D(a.TEXTURE_3D, 0, 0, 0, 0, ye.width, ye.height, ye.depth, Re, Pe, ye.data)) : t.texImage3D(a.TEXTURE_3D, 0, Ue, ye.width, ye.height, ye.depth, 0, Re, Pe, ye.data);
      else if (y.isFramebufferTexture) {
        if (je)
          if (Fe)
            t.texStorage2D(a.TEXTURE_2D, _e, Ue, ye.width, ye.height);
          else {
            let se = ye.width, Ee = ye.height;
            for (let Ae = 0; Ae < _e; Ae++)
              t.texImage2D(a.TEXTURE_2D, Ae, Ue, se, Ee, 0, Re, Pe, null), se >>= 1, Ee >>= 1;
          }
      } else if (ze.length > 0) {
        if (Fe && je) {
          const se = me(ze[0]);
          t.texStorage2D(a.TEXTURE_2D, _e, Ue, se.width, se.height);
        }
        for (let se = 0, Ee = ze.length; se < Ee; se++)
          Me = ze[se], Fe ? X && t.texSubImage2D(a.TEXTURE_2D, se, 0, 0, Re, Pe, Me) : t.texImage2D(a.TEXTURE_2D, se, Ue, Re, Pe, Me);
        y.generateMipmaps = !1;
      } else if (Fe) {
        if (je) {
          const se = me(ye);
          t.texStorage2D(a.TEXTURE_2D, _e, Ue, se.width, se.height);
        }
        X && t.texSubImage2D(a.TEXTURE_2D, 0, 0, 0, Re, Pe, ye);
      } else
        t.texImage2D(a.TEXTURE_2D, 0, Ue, Re, Pe, ye);
      m(y) && p($), Se.__version = oe.version, y.onUpdate && y.onUpdate(y);
    }
    M.__version = y.version;
  }
  function U(M, y, H) {
    if (y.image.length !== 6) return;
    const $ = ie(M, y), ee = y.source;
    t.bindTexture(a.TEXTURE_CUBE_MAP, M.__webglTexture, a.TEXTURE0 + H);
    const oe = r.get(ee);
    if (ee.version !== oe.__version || $ === !0) {
      t.activeTexture(a.TEXTURE0 + H);
      const Se = $e.getPrimaries($e.workingColorSpace), de = y.colorSpace === Tn ? null : $e.getPrimaries(y.colorSpace), xe = y.colorSpace === Tn || Se === de ? a.NONE : a.BROWSER_DEFAULT_WEBGL;
      a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL, y.flipY), a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL, y.premultiplyAlpha), a.pixelStorei(a.UNPACK_ALIGNMENT, y.unpackAlignment), a.pixelStorei(a.UNPACK_COLORSPACE_CONVERSION_WEBGL, xe);
      const De = y.isCompressedTexture || y.image[0].isCompressedTexture, ye = y.image[0] && y.image[0].isDataTexture, Re = [];
      for (let Ee = 0; Ee < 6; Ee++)
        !De && !ye ? Re[Ee] = v(y.image[Ee], !0, n.maxCubemapSize) : Re[Ee] = ye ? y.image[Ee].image : y.image[Ee], Re[Ee] = Te(y, Re[Ee]);
      const Pe = Re[0], Ue = i.convert(y.format, y.colorSpace), Me = i.convert(y.type), ze = x(y.internalFormat, Ue, Me, y.colorSpace), Fe = y.isVideoTexture !== !0, je = oe.__version === void 0 || $ === !0, X = ee.dataReady;
      let _e = D(y, Pe);
      Y(a.TEXTURE_CUBE_MAP, y);
      let se;
      if (De) {
        Fe && je && t.texStorage2D(a.TEXTURE_CUBE_MAP, _e, ze, Pe.width, Pe.height);
        for (let Ee = 0; Ee < 6; Ee++) {
          se = Re[Ee].mipmaps;
          for (let Ae = 0; Ae < se.length; Ae++) {
            const be = se[Ae];
            y.format !== 1023 ? Ue !== null ? Fe ? X && t.compressedTexSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, Ae, 0, 0, be.width, be.height, Ue, be.data) : t.compressedTexImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, Ae, ze, be.width, be.height, 0, be.data) : console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()") : Fe ? X && t.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, Ae, 0, 0, be.width, be.height, Ue, Me, be.data) : t.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, Ae, ze, be.width, be.height, 0, Ue, Me, be.data);
          }
        }
      } else {
        if (se = y.mipmaps, Fe && je) {
          se.length > 0 && _e++;
          const Ee = me(Re[0]);
          t.texStorage2D(a.TEXTURE_CUBE_MAP, _e, ze, Ee.width, Ee.height);
        }
        for (let Ee = 0; Ee < 6; Ee++)
          if (ye) {
            Fe ? X && t.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, 0, 0, 0, Re[Ee].width, Re[Ee].height, Ue, Me, Re[Ee].data) : t.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, 0, ze, Re[Ee].width, Re[Ee].height, 0, Ue, Me, Re[Ee].data);
            for (let Ae = 0; Ae < se.length; Ae++) {
              const Ne = se[Ae].image[Ee].image;
              Fe ? X && t.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, Ae + 1, 0, 0, Ne.width, Ne.height, Ue, Me, Ne.data) : t.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, Ae + 1, ze, Ne.width, Ne.height, 0, Ue, Me, Ne.data);
            }
          } else {
            Fe ? X && t.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, 0, 0, 0, Ue, Me, Re[Ee]) : t.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, 0, ze, Ue, Me, Re[Ee]);
            for (let Ae = 0; Ae < se.length; Ae++) {
              const be = se[Ae];
              Fe ? X && t.texSubImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, Ae + 1, 0, 0, Ue, Me, be.image[Ee]) : t.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X + Ee, Ae + 1, ze, Ue, Me, be.image[Ee]);
            }
          }
      }
      m(y) && p(a.TEXTURE_CUBE_MAP), oe.__version = ee.version, y.onUpdate && y.onUpdate(y);
    }
    M.__version = y.version;
  }
  function G(M, y, H, $, ee, oe) {
    const Se = i.convert(H.format, H.colorSpace), de = i.convert(H.type), xe = x(H.internalFormat, Se, de, H.colorSpace), De = r.get(y), ye = r.get(H);
    if (ye.__renderTarget = y, !De.__hasExternalTextures) {
      const Re = Math.max(1, y.width >> oe), Pe = Math.max(1, y.height >> oe);
      ee === a.TEXTURE_3D || ee === a.TEXTURE_2D_ARRAY ? t.texImage3D(ee, oe, xe, Re, Pe, y.depth, 0, Se, de, null) : t.texImage2D(ee, oe, xe, Re, Pe, 0, Se, de, null);
    }
    t.bindFramebuffer(a.FRAMEBUFFER, M), ve(y) ? o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER, $, ee, ye.__webglTexture, 0, ae(y)) : (ee === a.TEXTURE_2D || ee >= a.TEXTURE_CUBE_MAP_POSITIVE_X && ee <= a.TEXTURE_CUBE_MAP_NEGATIVE_Z) && a.framebufferTexture2D(a.FRAMEBUFFER, $, ee, ye.__webglTexture, oe), t.bindFramebuffer(a.FRAMEBUFFER, null);
  }
  function I(M, y, H) {
    if (a.bindRenderbuffer(a.RENDERBUFFER, M), y.depthBuffer) {
      const $ = y.depthTexture, ee = $ && $.isDepthTexture ? $.type : null, oe = _(y.stencilBuffer, ee), Se = y.stencilBuffer ? a.DEPTH_STENCIL_ATTACHMENT : a.DEPTH_ATTACHMENT, de = ae(y);
      ve(y) ? o.renderbufferStorageMultisampleEXT(a.RENDERBUFFER, de, oe, y.width, y.height) : H ? a.renderbufferStorageMultisample(a.RENDERBUFFER, de, oe, y.width, y.height) : a.renderbufferStorage(a.RENDERBUFFER, oe, y.width, y.height), a.framebufferRenderbuffer(a.FRAMEBUFFER, Se, a.RENDERBUFFER, M);
    } else {
      const $ = y.textures;
      for (let ee = 0; ee < $.length; ee++) {
        const oe = $[ee], Se = i.convert(oe.format, oe.colorSpace), de = i.convert(oe.type), xe = x(oe.internalFormat, Se, de, oe.colorSpace), De = ae(y);
        H && ve(y) === !1 ? a.renderbufferStorageMultisample(a.RENDERBUFFER, De, xe, y.width, y.height) : ve(y) ? o.renderbufferStorageMultisampleEXT(a.RENDERBUFFER, De, xe, y.width, y.height) : a.renderbufferStorage(a.RENDERBUFFER, xe, y.width, y.height);
      }
    }
    a.bindRenderbuffer(a.RENDERBUFFER, null);
  }
  function V(M, y) {
    if (y && y.isWebGLCubeRenderTarget) throw new Error("Depth Texture with cube render targets is not supported");
    if (t.bindFramebuffer(a.FRAMEBUFFER, M), !(y.depthTexture && y.depthTexture.isDepthTexture))
      throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");
    const $ = r.get(y.depthTexture);
    $.__renderTarget = y, (!$.__webglTexture || y.depthTexture.image.width !== y.width || y.depthTexture.image.height !== y.height) && (y.depthTexture.image.width = y.width, y.depthTexture.image.height = y.height, y.depthTexture.needsUpdate = !0), O(y.depthTexture, 0);
    const ee = $.__webglTexture, oe = ae(y);
    if (y.depthTexture.format === 1026)
      ve(y) ? o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER, a.DEPTH_ATTACHMENT, a.TEXTURE_2D, ee, 0, oe) : a.framebufferTexture2D(a.FRAMEBUFFER, a.DEPTH_ATTACHMENT, a.TEXTURE_2D, ee, 0);
    else if (y.depthTexture.format === 1027)
      ve(y) ? o.framebufferTexture2DMultisampleEXT(a.FRAMEBUFFER, a.DEPTH_STENCIL_ATTACHMENT, a.TEXTURE_2D, ee, 0, oe) : a.framebufferTexture2D(a.FRAMEBUFFER, a.DEPTH_STENCIL_ATTACHMENT, a.TEXTURE_2D, ee, 0);
    else
      throw new Error("Unknown depthTexture format");
  }
  function re(M) {
    const y = r.get(M), H = M.isWebGLCubeRenderTarget === !0;
    if (y.__boundDepthTexture !== M.depthTexture) {
      const $ = M.depthTexture;
      if (y.__depthDisposeCallback && y.__depthDisposeCallback(), $) {
        const ee = () => {
          delete y.__boundDepthTexture, delete y.__depthDisposeCallback, $.removeEventListener("dispose", ee);
        };
        $.addEventListener("dispose", ee), y.__depthDisposeCallback = ee;
      }
      y.__boundDepthTexture = $;
    }
    if (M.depthTexture && !y.__autoAllocateDepthBuffer) {
      if (H) throw new Error("target.depthTexture not supported in Cube render targets");
      V(y.__webglFramebuffer, M);
    } else if (H) {
      y.__webglDepthbuffer = [];
      for (let $ = 0; $ < 6; $++)
        if (t.bindFramebuffer(a.FRAMEBUFFER, y.__webglFramebuffer[$]), y.__webglDepthbuffer[$] === void 0)
          y.__webglDepthbuffer[$] = a.createRenderbuffer(), I(y.__webglDepthbuffer[$], M, !1);
        else {
          const ee = M.stencilBuffer ? a.DEPTH_STENCIL_ATTACHMENT : a.DEPTH_ATTACHMENT, oe = y.__webglDepthbuffer[$];
          a.bindRenderbuffer(a.RENDERBUFFER, oe), a.framebufferRenderbuffer(a.FRAMEBUFFER, ee, a.RENDERBUFFER, oe);
        }
    } else if (t.bindFramebuffer(a.FRAMEBUFFER, y.__webglFramebuffer), y.__webglDepthbuffer === void 0)
      y.__webglDepthbuffer = a.createRenderbuffer(), I(y.__webglDepthbuffer, M, !1);
    else {
      const $ = M.stencilBuffer ? a.DEPTH_STENCIL_ATTACHMENT : a.DEPTH_ATTACHMENT, ee = y.__webglDepthbuffer;
      a.bindRenderbuffer(a.RENDERBUFFER, ee), a.framebufferRenderbuffer(a.FRAMEBUFFER, $, a.RENDERBUFFER, ee);
    }
    t.bindFramebuffer(a.FRAMEBUFFER, null);
  }
  function he(M, y, H) {
    const $ = r.get(M);
    y !== void 0 && G($.__webglFramebuffer, M, M.texture, a.COLOR_ATTACHMENT0, a.TEXTURE_2D, 0), H !== void 0 && re(M);
  }
  function fe(M) {
    const y = M.texture, H = r.get(M), $ = r.get(y);
    M.addEventListener("dispose", A);
    const ee = M.textures, oe = M.isWebGLCubeRenderTarget === !0, Se = ee.length > 1;
    if (Se || ($.__webglTexture === void 0 && ($.__webglTexture = a.createTexture()), $.__version = y.version, s.memory.textures++), oe) {
      H.__webglFramebuffer = [];
      for (let de = 0; de < 6; de++)
        if (y.mipmaps && y.mipmaps.length > 0) {
          H.__webglFramebuffer[de] = [];
          for (let xe = 0; xe < y.mipmaps.length; xe++)
            H.__webglFramebuffer[de][xe] = a.createFramebuffer();
        } else
          H.__webglFramebuffer[de] = a.createFramebuffer();
    } else {
      if (y.mipmaps && y.mipmaps.length > 0) {
        H.__webglFramebuffer = [];
        for (let de = 0; de < y.mipmaps.length; de++)
          H.__webglFramebuffer[de] = a.createFramebuffer();
      } else
        H.__webglFramebuffer = a.createFramebuffer();
      if (Se)
        for (let de = 0, xe = ee.length; de < xe; de++) {
          const De = r.get(ee[de]);
          De.__webglTexture === void 0 && (De.__webglTexture = a.createTexture(), s.memory.textures++);
        }
      if (M.samples > 0 && ve(M) === !1) {
        H.__webglMultisampledFramebuffer = a.createFramebuffer(), H.__webglColorRenderbuffer = [], t.bindFramebuffer(a.FRAMEBUFFER, H.__webglMultisampledFramebuffer);
        for (let de = 0; de < ee.length; de++) {
          const xe = ee[de];
          H.__webglColorRenderbuffer[de] = a.createRenderbuffer(), a.bindRenderbuffer(a.RENDERBUFFER, H.__webglColorRenderbuffer[de]);
          const De = i.convert(xe.format, xe.colorSpace), ye = i.convert(xe.type), Re = x(xe.internalFormat, De, ye, xe.colorSpace, M.isXRRenderTarget === !0), Pe = ae(M);
          a.renderbufferStorageMultisample(a.RENDERBUFFER, Pe, Re, M.width, M.height), a.framebufferRenderbuffer(a.FRAMEBUFFER, a.COLOR_ATTACHMENT0 + de, a.RENDERBUFFER, H.__webglColorRenderbuffer[de]);
        }
        a.bindRenderbuffer(a.RENDERBUFFER, null), M.depthBuffer && (H.__webglDepthRenderbuffer = a.createRenderbuffer(), I(H.__webglDepthRenderbuffer, M, !0)), t.bindFramebuffer(a.FRAMEBUFFER, null);
      }
    }
    if (oe) {
      t.bindTexture(a.TEXTURE_CUBE_MAP, $.__webglTexture), Y(a.TEXTURE_CUBE_MAP, y);
      for (let de = 0; de < 6; de++)
        if (y.mipmaps && y.mipmaps.length > 0)
          for (let xe = 0; xe < y.mipmaps.length; xe++)
            G(H.__webglFramebuffer[de][xe], M, y, a.COLOR_ATTACHMENT0, a.TEXTURE_CUBE_MAP_POSITIVE_X + de, xe);
        else
          G(H.__webglFramebuffer[de], M, y, a.COLOR_ATTACHMENT0, a.TEXTURE_CUBE_MAP_POSITIVE_X + de, 0);
      m(y) && p(a.TEXTURE_CUBE_MAP), t.unbindTexture();
    } else if (Se) {
      for (let de = 0, xe = ee.length; de < xe; de++) {
        const De = ee[de], ye = r.get(De);
        t.bindTexture(a.TEXTURE_2D, ye.__webglTexture), Y(a.TEXTURE_2D, De), G(H.__webglFramebuffer, M, De, a.COLOR_ATTACHMENT0 + de, a.TEXTURE_2D, 0), m(De) && p(a.TEXTURE_2D);
      }
      t.unbindTexture();
    } else {
      let de = a.TEXTURE_2D;
      if ((M.isWebGL3DRenderTarget || M.isWebGLArrayRenderTarget) && (de = M.isWebGL3DRenderTarget ? a.TEXTURE_3D : a.TEXTURE_2D_ARRAY), t.bindTexture(de, $.__webglTexture), Y(de, y), y.mipmaps && y.mipmaps.length > 0)
        for (let xe = 0; xe < y.mipmaps.length; xe++)
          G(H.__webglFramebuffer[xe], M, y, a.COLOR_ATTACHMENT0, de, xe);
      else
        G(H.__webglFramebuffer, M, y, a.COLOR_ATTACHMENT0, de, 0);
      m(y) && p(de), t.unbindTexture();
    }
    M.depthBuffer && re(M);
  }
  function W(M) {
    const y = M.textures;
    for (let H = 0, $ = y.length; H < $; H++) {
      const ee = y[H];
      if (m(ee)) {
        const oe = T(M), Se = r.get(ee).__webglTexture;
        t.bindTexture(oe, Se), p(oe), t.unbindTexture();
      }
    }
  }
  const ce = [], P = [];
  function pe(M) {
    if (M.samples > 0) {
      if (ve(M) === !1) {
        const y = M.textures, H = M.width, $ = M.height;
        let ee = a.COLOR_BUFFER_BIT;
        const oe = M.stencilBuffer ? a.DEPTH_STENCIL_ATTACHMENT : a.DEPTH_ATTACHMENT, Se = r.get(M), de = y.length > 1;
        if (de)
          for (let xe = 0; xe < y.length; xe++)
            t.bindFramebuffer(a.FRAMEBUFFER, Se.__webglMultisampledFramebuffer), a.framebufferRenderbuffer(a.FRAMEBUFFER, a.COLOR_ATTACHMENT0 + xe, a.RENDERBUFFER, null), t.bindFramebuffer(a.FRAMEBUFFER, Se.__webglFramebuffer), a.framebufferTexture2D(a.DRAW_FRAMEBUFFER, a.COLOR_ATTACHMENT0 + xe, a.TEXTURE_2D, null, 0);
        t.bindFramebuffer(a.READ_FRAMEBUFFER, Se.__webglMultisampledFramebuffer), t.bindFramebuffer(a.DRAW_FRAMEBUFFER, Se.__webglFramebuffer);
        for (let xe = 0; xe < y.length; xe++) {
          if (M.resolveDepthBuffer && (M.depthBuffer && (ee |= a.DEPTH_BUFFER_BIT), M.stencilBuffer && M.resolveStencilBuffer && (ee |= a.STENCIL_BUFFER_BIT)), de) {
            a.framebufferRenderbuffer(a.READ_FRAMEBUFFER, a.COLOR_ATTACHMENT0, a.RENDERBUFFER, Se.__webglColorRenderbuffer[xe]);
            const De = r.get(y[xe]).__webglTexture;
            a.framebufferTexture2D(a.DRAW_FRAMEBUFFER, a.COLOR_ATTACHMENT0, a.TEXTURE_2D, De, 0);
          }
          a.blitFramebuffer(0, 0, H, $, 0, 0, H, $, ee, a.NEAREST), l === !0 && (ce.length = 0, P.length = 0, ce.push(a.COLOR_ATTACHMENT0 + xe), M.depthBuffer && M.resolveDepthBuffer === !1 && (ce.push(oe), P.push(oe), a.invalidateFramebuffer(a.DRAW_FRAMEBUFFER, P)), a.invalidateFramebuffer(a.READ_FRAMEBUFFER, ce));
        }
        if (t.bindFramebuffer(a.READ_FRAMEBUFFER, null), t.bindFramebuffer(a.DRAW_FRAMEBUFFER, null), de)
          for (let xe = 0; xe < y.length; xe++) {
            t.bindFramebuffer(a.FRAMEBUFFER, Se.__webglMultisampledFramebuffer), a.framebufferRenderbuffer(a.FRAMEBUFFER, a.COLOR_ATTACHMENT0 + xe, a.RENDERBUFFER, Se.__webglColorRenderbuffer[xe]);
            const De = r.get(y[xe]).__webglTexture;
            t.bindFramebuffer(a.FRAMEBUFFER, Se.__webglFramebuffer), a.framebufferTexture2D(a.DRAW_FRAMEBUFFER, a.COLOR_ATTACHMENT0 + xe, a.TEXTURE_2D, De, 0);
          }
        t.bindFramebuffer(a.DRAW_FRAMEBUFFER, Se.__webglMultisampledFramebuffer);
      } else if (M.depthBuffer && M.resolveDepthBuffer === !1 && l) {
        const y = M.stencilBuffer ? a.DEPTH_STENCIL_ATTACHMENT : a.DEPTH_ATTACHMENT;
        a.invalidateFramebuffer(a.DRAW_FRAMEBUFFER, [y]);
      }
    }
  }
  function ae(M) {
    return Math.min(n.maxSamples, M.samples);
  }
  function ve(M) {
    const y = r.get(M);
    return M.samples > 0 && e.has("WEBGL_multisampled_render_to_texture") === !0 && y.__useRenderToTexture !== !1;
  }
  function te(M) {
    const y = s.render.frame;
    u.get(M) !== y && (u.set(M, y), M.update());
  }
  function Te(M, y) {
    const H = M.colorSpace, $ = M.format, ee = M.type;
    return M.isCompressedTexture === !0 || M.isVideoTexture === !0 || H !== pi && H !== Tn && ($e.getTransfer(H) === it ? ($ !== 1023 || ee !== 1009) && console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.") : console.error("THREE.WebGLTextures: Unsupported texture color space:", H)), y;
  }
  function me(M) {
    return typeof HTMLImageElement < "u" && M instanceof HTMLImageElement ? (c.width = M.naturalWidth || M.width, c.height = M.naturalHeight || M.height) : typeof VideoFrame < "u" && M instanceof VideoFrame ? (c.width = M.displayWidth, c.height = M.displayHeight) : (c.width = M.width, c.height = M.height), c;
  }
  this.allocateTextureUnit = B, this.resetTextureUnits = L, this.setTexture2D = O, this.setTexture2DArray = z, this.setTexture3D = ne, this.setTextureCube = q, this.rebindTextures = he, this.setupRenderTarget = fe, this.updateRenderTargetMipmap = W, this.updateMultisampleRenderTarget = pe, this.setupDepthRenderbuffer = re, this.setupFrameBufferTexture = G, this.useMultisampledRTT = ve;
}
function bd(a, e) {
  function t(r, n = Tn) {
    let i;
    const s = $e.getTransfer(n);
    if (r === 1009) return a.UNSIGNED_BYTE;
    if (r === 1017) return a.UNSIGNED_SHORT_4_4_4_4;
    if (r === 1018) return a.UNSIGNED_SHORT_5_5_5_1;
    if (r === 35902) return a.UNSIGNED_INT_5_9_9_9_REV;
    if (r === 1010) return a.BYTE;
    if (r === 1011) return a.SHORT;
    if (r === 1012) return a.UNSIGNED_SHORT;
    if (r === 1013) return a.INT;
    if (r === 1014) return a.UNSIGNED_INT;
    if (r === 1015) return a.FLOAT;
    if (r === 1016) return a.HALF_FLOAT;
    if (r === 1021) return a.ALPHA;
    if (r === 1022) return a.RGB;
    if (r === 1023) return a.RGBA;
    if (r === 1024) return a.LUMINANCE;
    if (r === 1025) return a.LUMINANCE_ALPHA;
    if (r === 1026) return a.DEPTH_COMPONENT;
    if (r === 1027) return a.DEPTH_STENCIL;
    if (r === 1028) return a.RED;
    if (r === 1029) return a.RED_INTEGER;
    if (r === 1030) return a.RG;
    if (r === 1031) return a.RG_INTEGER;
    if (r === 1033) return a.RGBA_INTEGER;
    if (r === 33776 || r === 33777 || r === 33778 || r === 33779)
      if (s === it)
        if (i = e.get("WEBGL_compressed_texture_s3tc_srgb"), i !== null) {
          if (r === 33776) return i.COMPRESSED_SRGB_S3TC_DXT1_EXT;
          if (r === 33777) return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
          if (r === 33778) return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
          if (r === 33779) return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
        } else
          return null;
      else if (i = e.get("WEBGL_compressed_texture_s3tc"), i !== null) {
        if (r === 33776) return i.COMPRESSED_RGB_S3TC_DXT1_EXT;
        if (r === 33777) return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;
        if (r === 33778) return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;
        if (r === 33779) return i.COMPRESSED_RGBA_S3TC_DXT5_EXT;
      } else
        return null;
    if (r === 35840 || r === 35841 || r === 35842 || r === 35843)
      if (i = e.get("WEBGL_compressed_texture_pvrtc"), i !== null) {
        if (r === 35840) return i.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
        if (r === 35841) return i.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
        if (r === 35842) return i.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
        if (r === 35843) return i.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
      } else
        return null;
    if (r === 36196 || r === 37492 || r === 37496)
      if (i = e.get("WEBGL_compressed_texture_etc"), i !== null) {
        if (r === 36196 || r === 37492) return s === it ? i.COMPRESSED_SRGB8_ETC2 : i.COMPRESSED_RGB8_ETC2;
        if (r === 37496) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : i.COMPRESSED_RGBA8_ETC2_EAC;
      } else
        return null;
    if (r === 37808 || r === 37809 || r === 37810 || r === 37811 || r === 37812 || r === 37813 || r === 37814 || r === 37815 || r === 37816 || r === 37817 || r === 37818 || r === 37819 || r === 37820 || r === 37821)
      if (i = e.get("WEBGL_compressed_texture_astc"), i !== null) {
        if (r === 37808) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : i.COMPRESSED_RGBA_ASTC_4x4_KHR;
        if (r === 37809) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : i.COMPRESSED_RGBA_ASTC_5x4_KHR;
        if (r === 37810) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : i.COMPRESSED_RGBA_ASTC_5x5_KHR;
        if (r === 37811) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : i.COMPRESSED_RGBA_ASTC_6x5_KHR;
        if (r === 37812) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : i.COMPRESSED_RGBA_ASTC_6x6_KHR;
        if (r === 37813) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : i.COMPRESSED_RGBA_ASTC_8x5_KHR;
        if (r === 37814) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : i.COMPRESSED_RGBA_ASTC_8x6_KHR;
        if (r === 37815) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : i.COMPRESSED_RGBA_ASTC_8x8_KHR;
        if (r === 37816) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : i.COMPRESSED_RGBA_ASTC_10x5_KHR;
        if (r === 37817) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : i.COMPRESSED_RGBA_ASTC_10x6_KHR;
        if (r === 37818) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : i.COMPRESSED_RGBA_ASTC_10x8_KHR;
        if (r === 37819) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : i.COMPRESSED_RGBA_ASTC_10x10_KHR;
        if (r === 37820) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : i.COMPRESSED_RGBA_ASTC_12x10_KHR;
        if (r === 37821) return s === it ? i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : i.COMPRESSED_RGBA_ASTC_12x12_KHR;
      } else
        return null;
    if (r === 36492 || r === 36494 || r === 36495)
      if (i = e.get("EXT_texture_compression_bptc"), i !== null) {
        if (r === 36492) return s === it ? i.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : i.COMPRESSED_RGBA_BPTC_UNORM_EXT;
        if (r === 36494) return i.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;
        if (r === 36495) return i.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT;
      } else
        return null;
    if (r === 36283 || r === 36284 || r === 36285 || r === 36286)
      if (i = e.get("EXT_texture_compression_rgtc"), i !== null) {
        if (r === 36492) return i.COMPRESSED_RED_RGTC1_EXT;
        if (r === 36284) return i.COMPRESSED_SIGNED_RED_RGTC1_EXT;
        if (r === 36285) return i.COMPRESSED_RED_GREEN_RGTC2_EXT;
        if (r === 36286) return i.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT;
      } else
        return null;
    return r === 1020 ? a.UNSIGNED_INT_24_8 : a[r] !== void 0 ? a[r] : null;
  }
  return { convert: t };
}
class Ad extends Qt {
  constructor(e = []) {
    super(), this.isArrayCamera = !0, this.cameras = e;
  }
}
class yr extends gt {
  constructor() {
    super(), this.isGroup = !0, this.type = "Group";
  }
}
const wd = { type: "move" };
class Pa {
  constructor() {
    this._targetRay = null, this._grip = null, this._hand = null;
  }
  getHandSpace() {
    return this._hand === null && (this._hand = new yr(), this._hand.matrixAutoUpdate = !1, this._hand.visible = !1, this._hand.joints = {}, this._hand.inputState = { pinching: !1 }), this._hand;
  }
  getTargetRaySpace() {
    return this._targetRay === null && (this._targetRay = new yr(), this._targetRay.matrixAutoUpdate = !1, this._targetRay.visible = !1, this._targetRay.hasLinearVelocity = !1, this._targetRay.linearVelocity = new j(), this._targetRay.hasAngularVelocity = !1, this._targetRay.angularVelocity = new j()), this._targetRay;
  }
  getGripSpace() {
    return this._grip === null && (this._grip = new yr(), this._grip.matrixAutoUpdate = !1, this._grip.visible = !1, this._grip.hasLinearVelocity = !1, this._grip.linearVelocity = new j(), this._grip.hasAngularVelocity = !1, this._grip.angularVelocity = new j()), this._grip;
  }
  dispatchEvent(e) {
    return this._targetRay !== null && this._targetRay.dispatchEvent(e), this._grip !== null && this._grip.dispatchEvent(e), this._hand !== null && this._hand.dispatchEvent(e), this;
  }
  connect(e) {
    if (e && e.hand) {
      const t = this._hand;
      if (t)
        for (const r of e.hand.values())
          this._getHandJoint(t, r);
    }
    return this.dispatchEvent({ type: "connected", data: e }), this;
  }
  disconnect(e) {
    return this.dispatchEvent({ type: "disconnected", data: e }), this._targetRay !== null && (this._targetRay.visible = !1), this._grip !== null && (this._grip.visible = !1), this._hand !== null && (this._hand.visible = !1), this;
  }
  update(e, t, r) {
    let n = null, i = null, s = null;
    const o = this._targetRay, l = this._grip, c = this._hand;
    if (e && t.session.visibilityState !== "visible-blurred") {
      if (c && e.hand) {
        s = !0;
        for (const v of e.hand.values()) {
          const m = t.getJointPose(v, r), p = this._getHandJoint(c, v);
          m !== null && (p.matrix.fromArray(m.transform.matrix), p.matrix.decompose(p.position, p.rotation, p.scale), p.matrixWorldNeedsUpdate = !0, p.jointRadius = m.radius), p.visible = m !== null;
        }
        const u = c.joints["index-finger-tip"], f = c.joints["thumb-tip"], h = u.position.distanceTo(f.position), d = 0.02, g = 5e-3;
        c.inputState.pinching && h > d + g ? (c.inputState.pinching = !1, this.dispatchEvent({
          type: "pinchend",
          handedness: e.handedness,
          target: this
        })) : !c.inputState.pinching && h <= d - g && (c.inputState.pinching = !0, this.dispatchEvent({
          type: "pinchstart",
          handedness: e.handedness,
          target: this
        }));
      } else
        l !== null && e.gripSpace && (i = t.getPose(e.gripSpace, r), i !== null && (l.matrix.fromArray(i.transform.matrix), l.matrix.decompose(l.position, l.rotation, l.scale), l.matrixWorldNeedsUpdate = !0, i.linearVelocity ? (l.hasLinearVelocity = !0, l.linearVelocity.copy(i.linearVelocity)) : l.hasLinearVelocity = !1, i.angularVelocity ? (l.hasAngularVelocity = !0, l.angularVelocity.copy(i.angularVelocity)) : l.hasAngularVelocity = !1));
      o !== null && (n = t.getPose(e.targetRaySpace, r), n === null && i !== null && (n = i), n !== null && (o.matrix.fromArray(n.transform.matrix), o.matrix.decompose(o.position, o.rotation, o.scale), o.matrixWorldNeedsUpdate = !0, n.linearVelocity ? (o.hasLinearVelocity = !0, o.linearVelocity.copy(n.linearVelocity)) : o.hasLinearVelocity = !1, n.angularVelocity ? (o.hasAngularVelocity = !0, o.angularVelocity.copy(n.angularVelocity)) : o.hasAngularVelocity = !1, this.dispatchEvent(wd)));
    }
    return o !== null && (o.visible = n !== null), l !== null && (l.visible = i !== null), c !== null && (c.visible = s !== null), this;
  }
  // private method
  _getHandJoint(e, t) {
    if (e.joints[t.jointName] === void 0) {
      const r = new yr();
      r.matrixAutoUpdate = !1, r.visible = !1, e.joints[t.jointName] = r, e.add(r);
    }
    return e.joints[t.jointName];
  }
}
const Cd = `
void main() {

	gl_Position = vec4( position, 1.0 );

}`, Rd = `
uniform sampler2DArray depthColor;
uniform float depthWidth;
uniform float depthHeight;

void main() {

	vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );

	if ( coord.x >= 1.0 ) {

		gl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;

	} else {

		gl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;

	}

}`;
class Pd {
  constructor() {
    this.texture = null, this.mesh = null, this.depthNear = 0, this.depthFar = 0;
  }
  init(e, t, r) {
    if (this.texture === null) {
      const n = new wt(), i = e.properties.get(n);
      i.__webglTexture = t.texture, (t.depthNear != r.depthNear || t.depthFar != r.depthFar) && (this.depthNear = t.depthNear, this.depthFar = t.depthFar), this.texture = n;
    }
  }
  getMesh(e) {
    if (this.texture !== null && this.mesh === null) {
      const t = e.cameras[0].viewport, r = new bn({
        vertexShader: Cd,
        fragmentShader: Rd,
        uniforms: {
          depthColor: { value: this.texture },
          depthWidth: { value: t.z },
          depthHeight: { value: t.w }
        }
      });
      this.mesh = new Nt(new zn(20, 20), r);
    }
    return this.mesh;
  }
  reset() {
    this.texture = null, this.mesh = null;
  }
  getDepthTexture() {
    return this.texture;
  }
}
class Ud extends Gn {
  constructor(e, t) {
    super();
    const r = this;
    let n = null, i = 1, s = null, o = "local-floor", l = 1, c = null, u = null, f = null, h = null, d = null, g = null;
    const v = new Pd(), m = t.getContextAttributes();
    let p = null, T = null;
    const x = [], _ = [], D = new Ce();
    let C = null;
    const A = new Qt();
    A.viewport = new ot();
    const R = new Qt();
    R.viewport = new ot();
    const E = [A, R], S = new Ad();
    let F = null, L = null;
    this.cameraAutoUpdate = !0, this.enabled = !1, this.isPresenting = !1, this.getController = function(b) {
      let U = x[b];
      return U === void 0 && (U = new Pa(), x[b] = U), U.getTargetRaySpace();
    }, this.getControllerGrip = function(b) {
      let U = x[b];
      return U === void 0 && (U = new Pa(), x[b] = U), U.getGripSpace();
    }, this.getHand = function(b) {
      let U = x[b];
      return U === void 0 && (U = new Pa(), x[b] = U), U.getHandSpace();
    };
    function B(b) {
      const U = _.indexOf(b.inputSource);
      if (U === -1)
        return;
      const G = x[U];
      G !== void 0 && (G.update(b.inputSource, b.frame, c || s), G.dispatchEvent({ type: b.type, data: b.inputSource }));
    }
    function k() {
      n.removeEventListener("select", B), n.removeEventListener("selectstart", B), n.removeEventListener("selectend", B), n.removeEventListener("squeeze", B), n.removeEventListener("squeezestart", B), n.removeEventListener("squeezeend", B), n.removeEventListener("end", k), n.removeEventListener("inputsourceschange", O);
      for (let b = 0; b < x.length; b++) {
        const U = _[b];
        U !== null && (_[b] = null, x[b].disconnect(U));
      }
      F = null, L = null, v.reset(), e.setRenderTarget(p), d = null, h = null, f = null, n = null, T = null, ie.stop(), r.isPresenting = !1, e.setPixelRatio(C), e.setSize(D.width, D.height, !1), r.dispatchEvent({ type: "sessionend" });
    }
    this.setFramebufferScaleFactor = function(b) {
      i = b, r.isPresenting === !0 && console.warn("THREE.WebXRManager: Cannot change framebuffer scale while presenting.");
    }, this.setReferenceSpaceType = function(b) {
      o = b, r.isPresenting === !0 && console.warn("THREE.WebXRManager: Cannot change reference space type while presenting.");
    }, this.getReferenceSpace = function() {
      return c || s;
    }, this.setReferenceSpace = function(b) {
      c = b;
    }, this.getBaseLayer = function() {
      return h !== null ? h : d;
    }, this.getBinding = function() {
      return f;
    }, this.getFrame = function() {
      return g;
    }, this.getSession = function() {
      return n;
    }, this.setSession = async function(b) {
      if (n = b, n !== null) {
        if (p = e.getRenderTarget(), n.addEventListener("select", B), n.addEventListener("selectstart", B), n.addEventListener("selectend", B), n.addEventListener("squeeze", B), n.addEventListener("squeezestart", B), n.addEventListener("squeezeend", B), n.addEventListener("end", k), n.addEventListener("inputsourceschange", O), m.xrCompatible !== !0 && await t.makeXRCompatible(), C = e.getPixelRatio(), e.getSize(D), n.renderState.layers === void 0) {
          const U = {
            antialias: m.antialias,
            alpha: !0,
            depth: m.depth,
            stencil: m.stencil,
            framebufferScaleFactor: i
          };
          d = new XRWebGLLayer(n, t, U), n.updateRenderState({ baseLayer: d }), e.setPixelRatio(1), e.setSize(d.framebufferWidth, d.framebufferHeight, !1), T = new Bn(
            d.framebufferWidth,
            d.framebufferHeight,
            {
              format: 1023,
              type: 1009,
              colorSpace: e.outputColorSpace,
              stencilBuffer: m.stencil
            }
          );
        } else {
          let U = null, G = null, I = null;
          m.depth && (I = m.stencil ? t.DEPTH24_STENCIL8 : t.DEPTH_COMPONENT24, U = m.stencil ? 1027 : 1026, G = m.stencil ? 1020 : 1014);
          const V = {
            colorFormat: t.RGBA8,
            depthFormat: I,
            scaleFactor: i
          };
          f = new XRWebGLBinding(n, t), h = f.createProjectionLayer(V), n.updateRenderState({ layers: [h] }), e.setPixelRatio(1), e.setSize(h.textureWidth, h.textureHeight, !1), T = new Bn(
            h.textureWidth,
            h.textureHeight,
            {
              format: 1023,
              type: 1009,
              depthTexture: new jo(h.textureWidth, h.textureHeight, G, void 0, void 0, void 0, void 0, void 0, void 0, U),
              stencilBuffer: m.stencil,
              colorSpace: e.outputColorSpace,
              samples: m.antialias ? 4 : 0,
              resolveDepthBuffer: h.ignoreDepthValues === !1
            }
          );
        }
        T.isXRRenderTarget = !0, this.setFoveation(l), c = null, s = await n.requestReferenceSpace(o), ie.setContext(n), ie.start(), r.isPresenting = !0, r.dispatchEvent({ type: "sessionstart" });
      }
    }, this.getEnvironmentBlendMode = function() {
      if (n !== null)
        return n.environmentBlendMode;
    }, this.getDepthTexture = function() {
      return v.getDepthTexture();
    };
    function O(b) {
      for (let U = 0; U < b.removed.length; U++) {
        const G = b.removed[U], I = _.indexOf(G);
        I >= 0 && (_[I] = null, x[I].disconnect(G));
      }
      for (let U = 0; U < b.added.length; U++) {
        const G = b.added[U];
        let I = _.indexOf(G);
        if (I === -1) {
          for (let re = 0; re < x.length; re++)
            if (re >= _.length) {
              _.push(G), I = re;
              break;
            } else if (_[re] === null) {
              _[re] = G, I = re;
              break;
            }
          if (I === -1) break;
        }
        const V = x[I];
        V && V.connect(G);
      }
    }
    const z = new j(), ne = new j();
    function q(b, U, G) {
      z.setFromMatrixPosition(U.matrixWorld), ne.setFromMatrixPosition(G.matrixWorld);
      const I = z.distanceTo(ne), V = U.projectionMatrix.elements, re = G.projectionMatrix.elements, he = V[14] / (V[10] - 1), fe = V[14] / (V[10] + 1), W = (V[9] + 1) / V[5], ce = (V[9] - 1) / V[5], P = (V[8] - 1) / V[0], pe = (re[8] + 1) / re[0], ae = he * P, ve = he * pe, te = I / (-P + pe), Te = te * -P;
      if (U.matrixWorld.decompose(b.position, b.quaternion, b.scale), b.translateX(Te), b.translateZ(te), b.matrixWorld.compose(b.position, b.quaternion, b.scale), b.matrixWorldInverse.copy(b.matrixWorld).invert(), V[10] === -1)
        b.projectionMatrix.copy(U.projectionMatrix), b.projectionMatrixInverse.copy(U.projectionMatrixInverse);
      else {
        const me = he + te, M = fe + te, y = ae - Te, H = ve + (I - Te), $ = W * fe / M * me, ee = ce * fe / M * me;
        b.projectionMatrix.makePerspective(y, H, $, ee, me, M), b.projectionMatrixInverse.copy(b.projectionMatrix).invert();
      }
    }
    function K(b, U) {
      U === null ? b.matrixWorld.copy(b.matrix) : b.matrixWorld.multiplyMatrices(U.matrixWorld, b.matrix), b.matrixWorldInverse.copy(b.matrixWorld).invert();
    }
    this.updateCamera = function(b) {
      if (n === null) return;
      let U = b.near, G = b.far;
      v.texture !== null && (v.depthNear > 0 && (U = v.depthNear), v.depthFar > 0 && (G = v.depthFar)), S.near = R.near = A.near = U, S.far = R.far = A.far = G, (F !== S.near || L !== S.far) && (n.updateRenderState({
        depthNear: S.near,
        depthFar: S.far
      }), F = S.near, L = S.far), A.layers.mask = b.layers.mask | 2, R.layers.mask = b.layers.mask | 4, S.layers.mask = A.layers.mask | R.layers.mask;
      const I = b.parent, V = S.cameras;
      K(S, I);
      for (let re = 0; re < V.length; re++)
        K(V[re], I);
      V.length === 2 ? q(S, A, R) : S.projectionMatrix.copy(A.projectionMatrix), Z(b, S, I);
    };
    function Z(b, U, G) {
      G === null ? b.matrix.copy(U.matrixWorld) : (b.matrix.copy(G.matrixWorld), b.matrix.invert(), b.matrix.multiply(U.matrixWorld)), b.matrix.decompose(b.position, b.quaternion, b.scale), b.updateMatrixWorld(!0), b.projectionMatrix.copy(U.projectionMatrix), b.projectionMatrixInverse.copy(U.projectionMatrixInverse), b.isPerspectiveCamera && (b.fov = ka * 2 * Math.atan(1 / b.projectionMatrix.elements[5]), b.zoom = 1);
    }
    this.getCamera = function() {
      return S;
    }, this.getFoveation = function() {
      if (!(h === null && d === null))
        return l;
    }, this.setFoveation = function(b) {
      l = b, h !== null && (h.fixedFoveation = b), d !== null && d.fixedFoveation !== void 0 && (d.fixedFoveation = b);
    }, this.hasDepthSensing = function() {
      return v.texture !== null;
    }, this.getDepthSensingMesh = function() {
      return v.getMesh(S);
    };
    let N = null;
    function Y(b, U) {
      if (u = U.getViewerPose(c || s), g = U, u !== null) {
        const G = u.views;
        d !== null && (e.setRenderTargetFramebuffer(T, d.framebuffer), e.setRenderTarget(T));
        let I = !1;
        G.length !== S.cameras.length && (S.cameras.length = 0, I = !0);
        for (let re = 0; re < G.length; re++) {
          const he = G[re];
          let fe = null;
          if (d !== null)
            fe = d.getViewport(he);
          else {
            const ce = f.getViewSubImage(h, he);
            fe = ce.viewport, re === 0 && (e.setRenderTargetTextures(
              T,
              ce.colorTexture,
              h.ignoreDepthValues ? void 0 : ce.depthStencilTexture
            ), e.setRenderTarget(T));
          }
          let W = E[re];
          W === void 0 && (W = new Qt(), W.layers.enable(re), W.viewport = new ot(), E[re] = W), W.matrix.fromArray(he.transform.matrix), W.matrix.decompose(W.position, W.quaternion, W.scale), W.projectionMatrix.fromArray(he.projectionMatrix), W.projectionMatrixInverse.copy(W.projectionMatrix).invert(), W.viewport.set(fe.x, fe.y, fe.width, fe.height), re === 0 && (S.matrix.copy(W.matrix), S.matrix.decompose(S.position, S.quaternion, S.scale)), I === !0 && S.cameras.push(W);
        }
        const V = n.enabledFeatures;
        if (V && V.includes("depth-sensing")) {
          const re = f.getDepthInformation(G[0]);
          re && re.isValid && re.texture && v.init(e, re, n.renderState);
        }
      }
      for (let G = 0; G < x.length; G++) {
        const I = _[G], V = x[G];
        I !== null && V !== void 0 && V.update(I, U, c || s);
      }
      N && N(b, U), U.detectedPlanes && r.dispatchEvent({ type: "planesdetected", data: U }), g = null;
    }
    const ie = new qo();
    ie.setAnimationLoop(Y), this.setAnimationLoop = function(b) {
      N = b;
    }, this.dispose = function() {
    };
  }
}
const Dn = /* @__PURE__ */ new mn(), Dd = /* @__PURE__ */ new st();
function Ld(a, e) {
  function t(m, p) {
    m.matrixAutoUpdate === !0 && m.updateMatrix(), p.value.copy(m.matrix);
  }
  function r(m, p) {
    p.color.getRGB(m.fogColor.value, Vo(a)), p.isFog ? (m.fogNear.value = p.near, m.fogFar.value = p.far) : p.isFogExp2 && (m.fogDensity.value = p.density);
  }
  function n(m, p, T, x, _) {
    p.isMeshBasicMaterial || p.isMeshLambertMaterial ? i(m, p) : p.isMeshToonMaterial ? (i(m, p), f(m, p)) : p.isMeshPhongMaterial ? (i(m, p), u(m, p)) : p.isMeshStandardMaterial ? (i(m, p), h(m, p), p.isMeshPhysicalMaterial && d(m, p, _)) : p.isMeshMatcapMaterial ? (i(m, p), g(m, p)) : p.isMeshDepthMaterial ? i(m, p) : p.isMeshDistanceMaterial ? (i(m, p), v(m, p)) : p.isMeshNormalMaterial ? i(m, p) : p.isLineBasicMaterial ? (s(m, p), p.isLineDashedMaterial && o(m, p)) : p.isPointsMaterial ? l(m, p, T, x) : p.isSpriteMaterial ? c(m, p) : p.isShadowMaterial ? (m.color.value.copy(p.color), m.opacity.value = p.opacity) : p.isShaderMaterial && (p.uniformsNeedUpdate = !1);
  }
  function i(m, p) {
    m.opacity.value = p.opacity, p.color && m.diffuse.value.copy(p.color), p.emissive && m.emissive.value.copy(p.emissive).multiplyScalar(p.emissiveIntensity), p.map && (m.map.value = p.map, t(p.map, m.mapTransform)), p.alphaMap && (m.alphaMap.value = p.alphaMap, t(p.alphaMap, m.alphaMapTransform)), p.bumpMap && (m.bumpMap.value = p.bumpMap, t(p.bumpMap, m.bumpMapTransform), m.bumpScale.value = p.bumpScale, p.side === 1 && (m.bumpScale.value *= -1)), p.normalMap && (m.normalMap.value = p.normalMap, t(p.normalMap, m.normalMapTransform), m.normalScale.value.copy(p.normalScale), p.side === 1 && m.normalScale.value.negate()), p.displacementMap && (m.displacementMap.value = p.displacementMap, t(p.displacementMap, m.displacementMapTransform), m.displacementScale.value = p.displacementScale, m.displacementBias.value = p.displacementBias), p.emissiveMap && (m.emissiveMap.value = p.emissiveMap, t(p.emissiveMap, m.emissiveMapTransform)), p.specularMap && (m.specularMap.value = p.specularMap, t(p.specularMap, m.specularMapTransform)), p.alphaTest > 0 && (m.alphaTest.value = p.alphaTest);
    const T = e.get(p), x = T.envMap, _ = T.envMapRotation;
    x && (m.envMap.value = x, Dn.copy(_), Dn.x *= -1, Dn.y *= -1, Dn.z *= -1, x.isCubeTexture && x.isRenderTargetTexture === !1 && (Dn.y *= -1, Dn.z *= -1), m.envMapRotation.value.setFromMatrix4(Dd.makeRotationFromEuler(Dn)), m.flipEnvMap.value = x.isCubeTexture && x.isRenderTargetTexture === !1 ? -1 : 1, m.reflectivity.value = p.reflectivity, m.ior.value = p.ior, m.refractionRatio.value = p.refractionRatio), p.lightMap && (m.lightMap.value = p.lightMap, m.lightMapIntensity.value = p.lightMapIntensity, t(p.lightMap, m.lightMapTransform)), p.aoMap && (m.aoMap.value = p.aoMap, m.aoMapIntensity.value = p.aoMapIntensity, t(p.aoMap, m.aoMapTransform));
  }
  function s(m, p) {
    m.diffuse.value.copy(p.color), m.opacity.value = p.opacity, p.map && (m.map.value = p.map, t(p.map, m.mapTransform));
  }
  function o(m, p) {
    m.dashSize.value = p.dashSize, m.totalSize.value = p.dashSize + p.gapSize, m.scale.value = p.scale;
  }
  function l(m, p, T, x) {
    m.diffuse.value.copy(p.color), m.opacity.value = p.opacity, m.size.value = p.size * T, m.scale.value = x * 0.5, p.map && (m.map.value = p.map, t(p.map, m.uvTransform)), p.alphaMap && (m.alphaMap.value = p.alphaMap, t(p.alphaMap, m.alphaMapTransform)), p.alphaTest > 0 && (m.alphaTest.value = p.alphaTest);
  }
  function c(m, p) {
    m.diffuse.value.copy(p.color), m.opacity.value = p.opacity, m.rotation.value = p.rotation, p.map && (m.map.value = p.map, t(p.map, m.mapTransform)), p.alphaMap && (m.alphaMap.value = p.alphaMap, t(p.alphaMap, m.alphaMapTransform)), p.alphaTest > 0 && (m.alphaTest.value = p.alphaTest);
  }
  function u(m, p) {
    m.specular.value.copy(p.specular), m.shininess.value = Math.max(p.shininess, 1e-4);
  }
  function f(m, p) {
    p.gradientMap && (m.gradientMap.value = p.gradientMap);
  }
  function h(m, p) {
    m.metalness.value = p.metalness, p.metalnessMap && (m.metalnessMap.value = p.metalnessMap, t(p.metalnessMap, m.metalnessMapTransform)), m.roughness.value = p.roughness, p.roughnessMap && (m.roughnessMap.value = p.roughnessMap, t(p.roughnessMap, m.roughnessMapTransform)), p.envMap && (m.envMapIntensity.value = p.envMapIntensity);
  }
  function d(m, p, T) {
    m.ior.value = p.ior, p.sheen > 0 && (m.sheenColor.value.copy(p.sheenColor).multiplyScalar(p.sheen), m.sheenRoughness.value = p.sheenRoughness, p.sheenColorMap && (m.sheenColorMap.value = p.sheenColorMap, t(p.sheenColorMap, m.sheenColorMapTransform)), p.sheenRoughnessMap && (m.sheenRoughnessMap.value = p.sheenRoughnessMap, t(p.sheenRoughnessMap, m.sheenRoughnessMapTransform))), p.clearcoat > 0 && (m.clearcoat.value = p.clearcoat, m.clearcoatRoughness.value = p.clearcoatRoughness, p.clearcoatMap && (m.clearcoatMap.value = p.clearcoatMap, t(p.clearcoatMap, m.clearcoatMapTransform)), p.clearcoatRoughnessMap && (m.clearcoatRoughnessMap.value = p.clearcoatRoughnessMap, t(p.clearcoatRoughnessMap, m.clearcoatRoughnessMapTransform)), p.clearcoatNormalMap && (m.clearcoatNormalMap.value = p.clearcoatNormalMap, t(p.clearcoatNormalMap, m.clearcoatNormalMapTransform), m.clearcoatNormalScale.value.copy(p.clearcoatNormalScale), p.side === 1 && m.clearcoatNormalScale.value.negate())), p.dispersion > 0 && (m.dispersion.value = p.dispersion), p.iridescence > 0 && (m.iridescence.value = p.iridescence, m.iridescenceIOR.value = p.iridescenceIOR, m.iridescenceThicknessMinimum.value = p.iridescenceThicknessRange[0], m.iridescenceThicknessMaximum.value = p.iridescenceThicknessRange[1], p.iridescenceMap && (m.iridescenceMap.value = p.iridescenceMap, t(p.iridescenceMap, m.iridescenceMapTransform)), p.iridescenceThicknessMap && (m.iridescenceThicknessMap.value = p.iridescenceThicknessMap, t(p.iridescenceThicknessMap, m.iridescenceThicknessMapTransform))), p.transmission > 0 && (m.transmission.value = p.transmission, m.transmissionSamplerMap.value = T.texture, m.transmissionSamplerSize.value.set(T.width, T.height), p.transmissionMap && (m.transmissionMap.value = p.transmissionMap, t(p.transmissionMap, m.transmissionMapTransform)), m.thickness.value = p.thickness, p.thicknessMap && (m.thicknessMap.value = p.thicknessMap, t(p.thicknessMap, m.thicknessMapTransform)), m.attenuationDistance.value = p.attenuationDistance, m.attenuationColor.value.copy(p.attenuationColor)), p.anisotropy > 0 && (m.anisotropyVector.value.set(p.anisotropy * Math.cos(p.anisotropyRotation), p.anisotropy * Math.sin(p.anisotropyRotation)), p.anisotropyMap && (m.anisotropyMap.value = p.anisotropyMap, t(p.anisotropyMap, m.anisotropyMapTransform))), m.specularIntensity.value = p.specularIntensity, m.specularColor.value.copy(p.specularColor), p.specularColorMap && (m.specularColorMap.value = p.specularColorMap, t(p.specularColorMap, m.specularColorMapTransform)), p.specularIntensityMap && (m.specularIntensityMap.value = p.specularIntensityMap, t(p.specularIntensityMap, m.specularIntensityMapTransform));
  }
  function g(m, p) {
    p.matcap && (m.matcap.value = p.matcap);
  }
  function v(m, p) {
    const T = e.get(p).light;
    m.referencePosition.value.setFromMatrixPosition(T.matrixWorld), m.nearDistance.value = T.shadow.camera.near, m.farDistance.value = T.shadow.camera.far;
  }
  return {
    refreshFogUniforms: r,
    refreshMaterialUniforms: n
  };
}
function Fd(a, e, t, r) {
  let n = {}, i = {}, s = [];
  const o = a.getParameter(a.MAX_UNIFORM_BUFFER_BINDINGS);
  function l(T, x) {
    const _ = x.program;
    r.uniformBlockBinding(T, _);
  }
  function c(T, x) {
    let _ = n[T.id];
    _ === void 0 && (g(T), _ = u(T), n[T.id] = _, T.addEventListener("dispose", m));
    const D = x.program;
    r.updateUBOMapping(T, D);
    const C = e.render.frame;
    i[T.id] !== C && (h(T), i[T.id] = C);
  }
  function u(T) {
    const x = f();
    T.__bindingPointIndex = x;
    const _ = a.createBuffer(), D = T.__size, C = T.usage;
    return a.bindBuffer(a.UNIFORM_BUFFER, _), a.bufferData(a.UNIFORM_BUFFER, D, C), a.bindBuffer(a.UNIFORM_BUFFER, null), a.bindBufferBase(a.UNIFORM_BUFFER, x, _), _;
  }
  function f() {
    for (let T = 0; T < o; T++)
      if (s.indexOf(T) === -1)
        return s.push(T), T;
    return console.error("THREE.WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."), 0;
  }
  function h(T) {
    const x = n[T.id], _ = T.uniforms, D = T.__cache;
    a.bindBuffer(a.UNIFORM_BUFFER, x);
    for (let C = 0, A = _.length; C < A; C++) {
      const R = Array.isArray(_[C]) ? _[C] : [_[C]];
      for (let E = 0, S = R.length; E < S; E++) {
        const F = R[E];
        if (d(F, C, E, D) === !0) {
          const L = F.__offset, B = Array.isArray(F.value) ? F.value : [F.value];
          let k = 0;
          for (let O = 0; O < B.length; O++) {
            const z = B[O], ne = v(z);
            typeof z == "number" || typeof z == "boolean" ? (F.__data[0] = z, a.bufferSubData(a.UNIFORM_BUFFER, L + k, F.__data)) : z.isMatrix3 ? (F.__data[0] = z.elements[0], F.__data[1] = z.elements[1], F.__data[2] = z.elements[2], F.__data[3] = 0, F.__data[4] = z.elements[3], F.__data[5] = z.elements[4], F.__data[6] = z.elements[5], F.__data[7] = 0, F.__data[8] = z.elements[6], F.__data[9] = z.elements[7], F.__data[10] = z.elements[8], F.__data[11] = 0) : (z.toArray(F.__data, k), k += ne.storage / Float32Array.BYTES_PER_ELEMENT);
          }
          a.bufferSubData(a.UNIFORM_BUFFER, L, F.__data);
        }
      }
    }
    a.bindBuffer(a.UNIFORM_BUFFER, null);
  }
  function d(T, x, _, D) {
    const C = T.value, A = x + "_" + _;
    if (D[A] === void 0)
      return typeof C == "number" || typeof C == "boolean" ? D[A] = C : D[A] = C.clone(), !0;
    {
      const R = D[A];
      if (typeof C == "number" || typeof C == "boolean") {
        if (R !== C)
          return D[A] = C, !0;
      } else if (R.equals(C) === !1)
        return R.copy(C), !0;
    }
    return !1;
  }
  function g(T) {
    const x = T.uniforms;
    let _ = 0;
    const D = 16;
    for (let A = 0, R = x.length; A < R; A++) {
      const E = Array.isArray(x[A]) ? x[A] : [x[A]];
      for (let S = 0, F = E.length; S < F; S++) {
        const L = E[S], B = Array.isArray(L.value) ? L.value : [L.value];
        for (let k = 0, O = B.length; k < O; k++) {
          const z = B[k], ne = v(z), q = _ % D, K = q % ne.boundary, Z = q + K;
          _ += K, Z !== 0 && D - Z < ne.storage && (_ += D - Z), L.__data = new Float32Array(ne.storage / Float32Array.BYTES_PER_ELEMENT), L.__offset = _, _ += ne.storage;
        }
      }
    }
    const C = _ % D;
    return C > 0 && (_ += D - C), T.__size = _, T.__cache = {}, this;
  }
  function v(T) {
    const x = {
      boundary: 0,
      // bytes
      storage: 0
      // bytes
    };
    return typeof T == "number" || typeof T == "boolean" ? (x.boundary = 4, x.storage = 4) : T.isVector2 ? (x.boundary = 8, x.storage = 8) : T.isVector3 || T.isColor ? (x.boundary = 16, x.storage = 12) : T.isVector4 ? (x.boundary = 16, x.storage = 16) : T.isMatrix3 ? (x.boundary = 48, x.storage = 48) : T.isMatrix4 ? (x.boundary = 64, x.storage = 64) : T.isTexture ? console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group.") : console.warn("THREE.WebGLRenderer: Unsupported uniform value type.", T), x;
  }
  function m(T) {
    const x = T.target;
    x.removeEventListener("dispose", m);
    const _ = s.indexOf(x.__bindingPointIndex);
    s.splice(_, 1), a.deleteBuffer(n[x.id]), delete n[x.id], delete i[x.id];
  }
  function p() {
    for (const T in n)
      a.deleteBuffer(n[T]);
    s = [], n = {}, i = {};
  }
  return {
    bind: l,
    update: c,
    dispose: p
  };
}
class Id {
  constructor(e = {}) {
    const {
      canvas: t = bl(),
      context: r = null,
      depth: n = !0,
      stencil: i = !1,
      alpha: s = !1,
      antialias: o = !1,
      premultipliedAlpha: l = !0,
      preserveDrawingBuffer: c = !1,
      powerPreference: u = "default",
      failIfMajorPerformanceCaveat: f = !1,
      reverseDepthBuffer: h = !1
    } = e;
    this.isWebGLRenderer = !0;
    let d;
    if (r !== null) {
      if (typeof WebGLRenderingContext < "u" && r instanceof WebGLRenderingContext)
        throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");
      d = r.getContextAttributes().alpha;
    } else
      d = s;
    const g = new Uint32Array(4), v = new Int32Array(4);
    let m = null, p = null;
    const T = [], x = [];
    this.domElement = t, this.debug = {
      /**
       * Enables error checking and reporting when shader programs are being compiled
       * @type {boolean}
       */
      checkShaderErrors: !0,
      /**
       * Callback for custom error reporting.
       * @type {?Function}
       */
      onShaderError: null
    }, this.autoClear = !0, this.autoClearColor = !0, this.autoClearDepth = !0, this.autoClearStencil = !0, this.sortObjects = !0, this.clippingPlanes = [], this.localClippingEnabled = !1, this._outputColorSpace = Xt, this.toneMapping = 0, this.toneMappingExposure = 1;
    const _ = this;
    let D = !1, C = 0, A = 0, R = null, E = -1, S = null;
    const F = new ot(), L = new ot();
    let B = null;
    const k = new Ke(0);
    let O = 0, z = t.width, ne = t.height, q = 1, K = null, Z = null;
    const N = new ot(0, 0, z, ne), Y = new ot(0, 0, z, ne);
    let ie = !1;
    const b = new Xo();
    let U = !1, G = !1;
    const I = new st(), V = new st(), re = new j(), he = new ot(), fe = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: !0 };
    let W = !1;
    function ce() {
      return R === null ? q : 1;
    }
    let P = r;
    function pe(w, Q) {
      return t.getContext(w, Q);
    }
    try {
      const w = {
        alpha: !0,
        depth: n,
        stencil: i,
        antialias: o,
        premultipliedAlpha: l,
        preserveDrawingBuffer: c,
        powerPreference: u,
        failIfMajorPerformanceCaveat: f
      };
      if ("setAttribute" in t && t.setAttribute("data-engine", `three.js r${Ka}`), t.addEventListener("webglcontextlost", Ee, !1), t.addEventListener("webglcontextrestored", Ae, !1), t.addEventListener("webglcontextcreationerror", be, !1), P === null) {
        const Q = "webgl2";
        if (P = pe(Q, w), P === null)
          throw pe(Q) ? new Error("Error creating WebGL context with your selected attributes.") : new Error("Error creating WebGL context.");
      }
    } catch (w) {
      throw console.error("THREE.WebGLRenderer: " + w.message), w;
    }
    let ae, ve, te, Te, me, M, y, H, $, ee, oe, Se, de, xe, De, ye, Re, Pe, Ue, Me, ze, Fe, je, X;
    function _e() {
      ae = new zh(P), ae.init(), Fe = new bd(P, ae), ve = new Ih(P, ae, e, Fe), te = new Md(P, ae), ve.reverseDepthBuffer && h && te.buffers.depth.setReversed(!0), Te = new Wh(P), me = new cd(), M = new Td(P, ae, te, me, ve, Fe, Te), y = new Oh(_), H = new Gh(_), $ = new Jl(P), je = new Lh(P, $), ee = new Vh(P, $, Te, je), oe = new qh(P, ee, $, Te), Ue = new Xh(P, ve, M), ye = new Nh(me), Se = new ld(_, y, H, ae, ve, je, ye), de = new Ld(_, me), xe = new hd(), De = new vd(ae), Pe = new Dh(_, y, H, te, oe, d, l), Re = new Sd(_, oe, ve), X = new Fd(P, Te, ve, te), Me = new Fh(P, ae, Te), ze = new Hh(P, ae, Te), Te.programs = Se.programs, _.capabilities = ve, _.extensions = ae, _.properties = me, _.renderLists = xe, _.shadowMap = Re, _.state = te, _.info = Te;
    }
    _e();
    const se = new Ud(_, P);
    this.xr = se, this.getContext = function() {
      return P;
    }, this.getContextAttributes = function() {
      return P.getContextAttributes();
    }, this.forceContextLoss = function() {
      const w = ae.get("WEBGL_lose_context");
      w && w.loseContext();
    }, this.forceContextRestore = function() {
      const w = ae.get("WEBGL_lose_context");
      w && w.restoreContext();
    }, this.getPixelRatio = function() {
      return q;
    }, this.setPixelRatio = function(w) {
      w !== void 0 && (q = w, this.setSize(z, ne, !1));
    }, this.getSize = function(w) {
      return w.set(z, ne);
    }, this.setSize = function(w, Q, ue = !0) {
      if (se.isPresenting) {
        console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting.");
        return;
      }
      z = w, ne = Q, t.width = Math.floor(w * q), t.height = Math.floor(Q * q), ue === !0 && (t.style.width = w + "px", t.style.height = Q + "px"), this.setViewport(0, 0, w, Q);
    }, this.getDrawingBufferSize = function(w) {
      return w.set(z * q, ne * q).floor();
    }, this.setDrawingBufferSize = function(w, Q, ue) {
      z = w, ne = Q, q = ue, t.width = Math.floor(w * ue), t.height = Math.floor(Q * ue), this.setViewport(0, 0, w, Q);
    }, this.getCurrentViewport = function(w) {
      return w.copy(F);
    }, this.getViewport = function(w) {
      return w.copy(N);
    }, this.setViewport = function(w, Q, ue, le) {
      w.isVector4 ? N.set(w.x, w.y, w.z, w.w) : N.set(w, Q, ue, le), te.viewport(F.copy(N).multiplyScalar(q).round());
    }, this.getScissor = function(w) {
      return w.copy(Y);
    }, this.setScissor = function(w, Q, ue, le) {
      w.isVector4 ? Y.set(w.x, w.y, w.z, w.w) : Y.set(w, Q, ue, le), te.scissor(L.copy(Y).multiplyScalar(q).round());
    }, this.getScissorTest = function() {
      return ie;
    }, this.setScissorTest = function(w) {
      te.setScissorTest(ie = w);
    }, this.setOpaqueSort = function(w) {
      K = w;
    }, this.setTransparentSort = function(w) {
      Z = w;
    }, this.getClearColor = function(w) {
      return w.copy(Pe.getClearColor());
    }, this.setClearColor = function() {
      Pe.setClearColor.apply(Pe, arguments);
    }, this.getClearAlpha = function() {
      return Pe.getClearAlpha();
    }, this.setClearAlpha = function() {
      Pe.setClearAlpha.apply(Pe, arguments);
    }, this.clear = function(w = !0, Q = !0, ue = !0) {
      let le = 0;
      if (w) {
        let J = !1;
        if (R !== null) {
          const we = R.texture.format;
          J = we === 1033 || we === 1031 || we === 1029;
        }
        if (J) {
          const we = R.texture.type, ge = we === 1009 || we === 1014 || we === 1012 || we === 1020 || we === 1017 || we === 1018, Ie = Pe.getClearColor(), Be = Pe.getClearAlpha(), He = Ie.r, qe = Ie.g, Oe = Ie.b;
          ge ? (g[0] = He, g[1] = qe, g[2] = Oe, g[3] = Be, P.clearBufferuiv(P.COLOR, 0, g)) : (v[0] = He, v[1] = qe, v[2] = Oe, v[3] = Be, P.clearBufferiv(P.COLOR, 0, v));
        } else
          le |= P.COLOR_BUFFER_BIT;
      }
      Q && (le |= P.DEPTH_BUFFER_BIT), ue && (le |= P.STENCIL_BUFFER_BIT, this.state.buffers.stencil.setMask(4294967295)), P.clear(le);
    }, this.clearColor = function() {
      this.clear(!0, !1, !1);
    }, this.clearDepth = function() {
      this.clear(!1, !0, !1);
    }, this.clearStencil = function() {
      this.clear(!1, !1, !0);
    }, this.dispose = function() {
      t.removeEventListener("webglcontextlost", Ee, !1), t.removeEventListener("webglcontextrestored", Ae, !1), t.removeEventListener("webglcontextcreationerror", be, !1), xe.dispose(), De.dispose(), me.dispose(), y.dispose(), H.dispose(), oe.dispose(), je.dispose(), X.dispose(), Se.dispose(), se.dispose(), se.removeEventListener("sessionstart", ct), se.removeEventListener("sessionend", Ct), yt.stop();
    };
    function Ee(w) {
      w.preventDefault(), console.log("THREE.WebGLRenderer: Context Lost."), D = !0;
    }
    function Ae() {
      console.log("THREE.WebGLRenderer: Context Restored."), D = !1;
      const w = Te.autoReset, Q = Re.enabled, ue = Re.autoUpdate, le = Re.needsUpdate, J = Re.type;
      _e(), Te.autoReset = w, Re.enabled = Q, Re.autoUpdate = ue, Re.needsUpdate = le, Re.type = J;
    }
    function be(w) {
      console.error("THREE.WebGLRenderer: A WebGL context could not be created. Reason: ", w.statusMessage);
    }
    function Ne(w) {
      const Q = w.target;
      Q.removeEventListener("dispose", Ne), We(Q);
    }
    function We(w) {
      Ge(w), me.remove(w);
    }
    function Ge(w) {
      const Q = me.get(w).programs;
      Q !== void 0 && (Q.forEach(function(ue) {
        Se.releaseProgram(ue);
      }), w.isShaderMaterial && Se.releaseShaderCache(w));
    }
    this.renderBufferDirect = function(w, Q, ue, le, J, we) {
      Q === null && (Q = fe);
      const ge = J.isMesh && J.matrixWorld.determinant() < 0, Ie = Xr(w, Q, ue, le, J);
      te.setMaterial(le, ge);
      let Be = ue.index, He = 1;
      if (le.wireframe === !0) {
        if (Be = ee.getWireframeAttribute(ue), Be === void 0) return;
        He = 2;
      }
      const qe = ue.drawRange, Oe = ue.attributes.position;
      let Ze = qe.start * He, et = (qe.start + qe.count) * He;
      we !== null && (Ze = Math.max(Ze, we.start * He), et = Math.min(et, (we.start + we.count) * He)), Be !== null ? (Ze = Math.max(Ze, 0), et = Math.min(et, Be.count)) : Oe != null && (Ze = Math.max(Ze, 0), et = Math.min(et, Oe.count));
      const tt = et - Ze;
      if (tt < 0 || tt === 1 / 0) return;
      je.setup(J, le, Ie, ue, Be);
      let vt, Je = Me;
      if (Be !== null && (vt = $.get(Be), Je = ze, Je.setIndex(vt)), J.isMesh)
        le.wireframe === !0 ? (te.setLineWidth(le.wireframeLinewidth * ce()), Je.setMode(P.LINES)) : Je.setMode(P.TRIANGLES);
      else if (J.isLine) {
        let ke = le.linewidth;
        ke === void 0 && (ke = 1), te.setLineWidth(ke * ce()), J.isLineSegments ? Je.setMode(P.LINES) : J.isLineLoop ? Je.setMode(P.LINE_LOOP) : Je.setMode(P.LINE_STRIP);
      } else J.isPoints ? Je.setMode(P.POINTS) : J.isSprite && Je.setMode(P.TRIANGLES);
      if (J.isBatchedMesh)
        if (J._multiDrawInstances !== null)
          Je.renderMultiDrawInstances(J._multiDrawStarts, J._multiDrawCounts, J._multiDrawCount, J._multiDrawInstances);
        else if (ae.get("WEBGL_multi_draw"))
          Je.renderMultiDraw(J._multiDrawStarts, J._multiDrawCounts, J._multiDrawCount);
        else {
          const ke = J._multiDrawStarts, Bt = J._multiDrawCounts, Qe = J._multiDrawCount, _t = Be ? $.get(Be).bytesPerElement : 1, rn = me.get(le).currentProgram.getUniforms();
          for (let ut = 0; ut < Qe; ut++)
            rn.setValue(P, "_gl_DrawID", ut), Je.render(ke[ut] / _t, Bt[ut]);
        }
      else if (J.isInstancedMesh)
        Je.renderInstances(Ze, tt, J.count);
      else if (ue.isInstancedBufferGeometry) {
        const ke = ue._maxInstanceCount !== void 0 ? ue._maxInstanceCount : 1 / 0, Bt = Math.min(ue.instanceCount, ke);
        Je.renderInstances(Ze, tt, Bt);
      } else
        Je.render(Ze, tt);
    };
    function Ve(w, Q, ue) {
      w.transparent === !0 && w.side === 2 && w.forceSinglePass === !1 ? (w.side = 1, w.needsUpdate = !0, Ht(w, Q, ue), w.side = 0, w.needsUpdate = !0, Ht(w, Q, ue), w.side = 2) : Ht(w, Q, ue);
    }
    this.compile = function(w, Q, ue = null) {
      ue === null && (ue = w), p = De.get(ue), p.init(Q), x.push(p), ue.traverseVisible(function(J) {
        J.isLight && J.layers.test(Q.layers) && (p.pushLight(J), J.castShadow && p.pushShadow(J));
      }), w !== ue && w.traverseVisible(function(J) {
        J.isLight && J.layers.test(Q.layers) && (p.pushLight(J), J.castShadow && p.pushShadow(J));
      }), p.setupLights();
      const le = /* @__PURE__ */ new Set();
      return w.traverse(function(J) {
        if (!(J.isMesh || J.isPoints || J.isLine || J.isSprite))
          return;
        const we = J.material;
        if (we)
          if (Array.isArray(we))
            for (let ge = 0; ge < we.length; ge++) {
              const Ie = we[ge];
              Ve(Ie, ue, J), le.add(Ie);
            }
          else
            Ve(we, ue, J), le.add(we);
      }), x.pop(), p = null, le;
    }, this.compileAsync = function(w, Q, ue = null) {
      const le = this.compile(w, Q, ue);
      return new Promise((J) => {
        function we() {
          if (le.forEach(function(ge) {
            me.get(ge).currentProgram.isReady() && le.delete(ge);
          }), le.size === 0) {
            J(w);
            return;
          }
          setTimeout(we, 10);
        }
        ae.get("KHR_parallel_shader_compile") !== null ? we() : setTimeout(we, 10);
      });
    };
    let rt = null;
    function at(w) {
      rt && rt(w);
    }
    function ct() {
      yt.stop();
    }
    function Ct() {
      yt.start();
    }
    const yt = new qo();
    yt.setAnimationLoop(at), typeof self < "u" && yt.setContext(self), this.setAnimationLoop = function(w) {
      rt = w, se.setAnimationLoop(w), w === null ? yt.stop() : yt.start();
    }, se.addEventListener("sessionstart", ct), se.addEventListener("sessionend", Ct), this.render = function(w, Q) {
      if (Q !== void 0 && Q.isCamera !== !0) {
        console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");
        return;
      }
      if (D === !0) return;
      if (w.matrixWorldAutoUpdate === !0 && w.updateMatrixWorld(), Q.parent === null && Q.matrixWorldAutoUpdate === !0 && Q.updateMatrixWorld(), se.enabled === !0 && se.isPresenting === !0 && (se.cameraAutoUpdate === !0 && se.updateCamera(Q), Q = se.getCamera()), w.isScene === !0 && w.onBeforeRender(_, w, Q, R), p = De.get(w, x.length), p.init(Q), x.push(p), V.multiplyMatrices(Q.projectionMatrix, Q.matrixWorldInverse), b.setFromProjectionMatrix(V), G = this.localClippingEnabled, U = ye.init(this.clippingPlanes, G), m = xe.get(w, T.length), m.init(), T.push(m), se.enabled === !0 && se.isPresenting === !0) {
        const we = _.xr.getDepthSensingMesh();
        we !== null && Ot(we, Q, -1 / 0, _.sortObjects);
      }
      Ot(w, Q, 0, _.sortObjects), m.finish(), _.sortObjects === !0 && m.sort(K, Z), W = se.enabled === !1 || se.isPresenting === !1 || se.hasDepthSensing() === !1, W && Pe.addToRenderList(m, w), this.info.render.frame++, U === !0 && ye.beginShadows();
      const ue = p.state.shadowsArray;
      Re.render(ue, w, Q), U === !0 && ye.endShadows(), this.info.autoReset === !0 && this.info.reset();
      const le = m.opaque, J = m.transmissive;
      if (p.setupLights(), Q.isArrayCamera) {
        const we = Q.cameras;
        if (J.length > 0)
          for (let ge = 0, Ie = we.length; ge < Ie; ge++) {
            const Be = we[ge];
            nn(le, J, w, Be);
          }
        W && Pe.render(w);
        for (let ge = 0, Ie = we.length; ge < Ie; ge++) {
          const Be = we[ge];
          qt(m, w, Be, Be.viewport);
        }
      } else
        J.length > 0 && nn(le, J, w, Q), W && Pe.render(w), qt(m, w, Q);
      R !== null && (M.updateMultisampleRenderTarget(R), M.updateRenderTargetMipmap(R)), w.isScene === !0 && w.onAfterRender(_, w, Q), je.resetDefaultState(), E = -1, S = null, x.pop(), x.length > 0 ? (p = x[x.length - 1], U === !0 && ye.setGlobalState(_.clippingPlanes, p.state.camera)) : p = null, T.pop(), T.length > 0 ? m = T[T.length - 1] : m = null;
    };
    function Ot(w, Q, ue, le) {
      if (w.visible === !1) return;
      if (w.layers.test(Q.layers)) {
        if (w.isGroup)
          ue = w.renderOrder;
        else if (w.isLOD)
          w.autoUpdate === !0 && w.update(Q);
        else if (w.isLight)
          p.pushLight(w), w.castShadow && p.pushShadow(w);
        else if (w.isSprite) {
          if (!w.frustumCulled || b.intersectsSprite(w)) {
            le && he.setFromMatrixPosition(w.matrixWorld).applyMatrix4(V);
            const ge = oe.update(w), Ie = w.material;
            Ie.visible && m.push(w, ge, Ie, ue, he.z, null);
          }
        } else if ((w.isMesh || w.isLine || w.isPoints) && (!w.frustumCulled || b.intersectsObject(w))) {
          const ge = oe.update(w), Ie = w.material;
          if (le && (w.boundingSphere !== void 0 ? (w.boundingSphere === null && w.computeBoundingSphere(), he.copy(w.boundingSphere.center)) : (ge.boundingSphere === null && ge.computeBoundingSphere(), he.copy(ge.boundingSphere.center)), he.applyMatrix4(w.matrixWorld).applyMatrix4(V)), Array.isArray(Ie)) {
            const Be = ge.groups;
            for (let He = 0, qe = Be.length; He < qe; He++) {
              const Oe = Be[He], Ze = Ie[Oe.materialIndex];
              Ze && Ze.visible && m.push(w, ge, Ze, ue, he.z, Oe);
            }
          } else Ie.visible && m.push(w, ge, Ie, ue, he.z, null);
        }
      }
      const we = w.children;
      for (let ge = 0, Ie = we.length; ge < Ie; ge++)
        Ot(we[ge], Q, ue, le);
    }
    function qt(w, Q, ue, le) {
      const J = w.opaque, we = w.transmissive, ge = w.transparent;
      p.setupLightsView(ue), U === !0 && ye.setGlobalState(_.clippingPlanes, ue), le && te.viewport(F.copy(le)), J.length > 0 && Rt(J, Q, ue), we.length > 0 && Rt(we, Q, ue), ge.length > 0 && Rt(ge, Q, ue), te.buffers.depth.setTest(!0), te.buffers.depth.setMask(!0), te.buffers.color.setMask(!0), te.setPolygonOffset(!1);
    }
    function nn(w, Q, ue, le) {
      if ((ue.isScene === !0 ? ue.overrideMaterial : null) !== null)
        return;
      p.state.transmissionRenderTarget[le.id] === void 0 && (p.state.transmissionRenderTarget[le.id] = new Bn(1, 1, {
        generateMipmaps: !0,
        type: ae.has("EXT_color_buffer_half_float") || ae.has("EXT_color_buffer_float") ? 1016 : 1009,
        minFilter: 1008,
        samples: 4,
        stencilBuffer: i,
        resolveDepthBuffer: !1,
        resolveStencilBuffer: !1,
        colorSpace: $e.workingColorSpace
      }));
      const we = p.state.transmissionRenderTarget[le.id], ge = le.viewport || F;
      we.setSize(ge.z, ge.w);
      const Ie = _.getRenderTarget();
      _.setRenderTarget(we), _.getClearColor(k), O = _.getClearAlpha(), O < 1 && _.setClearColor(16777215, 0.5), _.clear(), W && Pe.render(ue);
      const Be = _.toneMapping;
      _.toneMapping = 0;
      const He = le.viewport;
      if (le.viewport !== void 0 && (le.viewport = void 0), p.setupLightsView(le), U === !0 && ye.setGlobalState(_.clippingPlanes, le), Rt(w, ue, le), M.updateMultisampleRenderTarget(we), M.updateRenderTargetMipmap(we), ae.has("WEBGL_multisampled_render_to_texture") === !1) {
        let qe = !1;
        for (let Oe = 0, Ze = Q.length; Oe < Ze; Oe++) {
          const et = Q[Oe], tt = et.object, vt = et.geometry, Je = et.material, ke = et.group;
          if (Je.side === 2 && tt.layers.test(le.layers)) {
            const Bt = Je.side;
            Je.side = 1, Je.needsUpdate = !0, pt(tt, ue, le, vt, Je, ke), Je.side = Bt, Je.needsUpdate = !0, qe = !0;
          }
        }
        qe === !0 && (M.updateMultisampleRenderTarget(we), M.updateRenderTargetMipmap(we));
      }
      _.setRenderTarget(Ie), _.setClearColor(k, O), He !== void 0 && (le.viewport = He), _.toneMapping = Be;
    }
    function Rt(w, Q, ue) {
      const le = Q.isScene === !0 ? Q.overrideMaterial : null;
      for (let J = 0, we = w.length; J < we; J++) {
        const ge = w[J], Ie = ge.object, Be = ge.geometry, He = le === null ? ge.material : le, qe = ge.group;
        Ie.layers.test(ue.layers) && pt(Ie, Q, ue, Be, He, qe);
      }
    }
    function pt(w, Q, ue, le, J, we) {
      w.onBeforeRender(_, Q, ue, le, J, we), w.modelViewMatrix.multiplyMatrices(ue.matrixWorldInverse, w.matrixWorld), w.normalMatrix.getNormalMatrix(w.modelViewMatrix), J.onBeforeRender(_, Q, ue, le, w, we), J.transparent === !0 && J.side === 2 && J.forceSinglePass === !1 ? (J.side = 1, J.needsUpdate = !0, _.renderBufferDirect(ue, Q, le, J, w, we), J.side = 0, J.needsUpdate = !0, _.renderBufferDirect(ue, Q, le, J, w, we), J.side = 2) : _.renderBufferDirect(ue, Q, le, J, w, we), w.onAfterRender(_, Q, ue, le, J, we);
    }
    function Ht(w, Q, ue) {
      Q.isScene !== !0 && (Q = fe);
      const le = me.get(w), J = p.state.lights, we = p.state.shadowsArray, ge = J.state.version, Ie = Se.getParameters(w, J.state, we, Q, ue), Be = Se.getProgramCacheKey(Ie);
      let He = le.programs;
      le.environment = w.isMeshStandardMaterial ? Q.environment : null, le.fog = Q.fog, le.envMap = (w.isMeshStandardMaterial ? H : y).get(w.envMap || le.environment), le.envMapRotation = le.environment !== null && w.envMap === null ? Q.environmentRotation : w.envMapRotation, He === void 0 && (w.addEventListener("dispose", Ne), He = /* @__PURE__ */ new Map(), le.programs = He);
      let qe = He.get(Be);
      if (qe !== void 0) {
        if (le.currentProgram === qe && le.lightsStateVersion === ge)
          return Vn(w, Ie), qe;
      } else
        Ie.uniforms = Se.getUniforms(w), w.onBeforeCompile(Ie, _), qe = Se.acquireProgram(Ie, Be), He.set(Be, qe), le.uniforms = Ie.uniforms;
      const Oe = le.uniforms;
      return (!w.isShaderMaterial && !w.isRawShaderMaterial || w.clipping === !0) && (Oe.clippingPlanes = ye.uniform), Vn(w, Ie), le.needsLights = Hn(w), le.lightsStateVersion = ge, le.needsLights && (Oe.ambientLightColor.value = J.state.ambient, Oe.lightProbe.value = J.state.probe, Oe.directionalLights.value = J.state.directional, Oe.directionalLightShadows.value = J.state.directionalShadow, Oe.spotLights.value = J.state.spot, Oe.spotLightShadows.value = J.state.spotShadow, Oe.rectAreaLights.value = J.state.rectArea, Oe.ltc_1.value = J.state.rectAreaLTC1, Oe.ltc_2.value = J.state.rectAreaLTC2, Oe.pointLights.value = J.state.point, Oe.pointLightShadows.value = J.state.pointShadow, Oe.hemisphereLights.value = J.state.hemi, Oe.directionalShadowMap.value = J.state.directionalShadowMap, Oe.directionalShadowMatrix.value = J.state.directionalShadowMatrix, Oe.spotShadowMap.value = J.state.spotShadowMap, Oe.spotLightMatrix.value = J.state.spotLightMatrix, Oe.spotLightMap.value = J.state.spotLightMap, Oe.pointShadowMap.value = J.state.pointShadowMap, Oe.pointShadowMatrix.value = J.state.pointShadowMatrix), le.currentProgram = qe, le.uniformsList = null, qe;
    }
    function Si(w) {
      if (w.uniformsList === null) {
        const Q = w.currentProgram.getUniforms();
        w.uniformsList = Dr.seqWithValue(Q.seq, w.uniforms);
      }
      return w.uniformsList;
    }
    function Vn(w, Q) {
      const ue = me.get(w);
      ue.outputColorSpace = Q.outputColorSpace, ue.batching = Q.batching, ue.batchingColor = Q.batchingColor, ue.instancing = Q.instancing, ue.instancingColor = Q.instancingColor, ue.instancingMorph = Q.instancingMorph, ue.skinning = Q.skinning, ue.morphTargets = Q.morphTargets, ue.morphNormals = Q.morphNormals, ue.morphColors = Q.morphColors, ue.morphTargetsCount = Q.morphTargetsCount, ue.numClippingPlanes = Q.numClippingPlanes, ue.numIntersection = Q.numClipIntersection, ue.vertexAlphas = Q.vertexAlphas, ue.vertexTangents = Q.vertexTangents, ue.toneMapping = Q.toneMapping;
    }
    function Xr(w, Q, ue, le, J) {
      Q.isScene !== !0 && (Q = fe), M.resetTextureUnits();
      const we = Q.fog, ge = le.isMeshStandardMaterial ? Q.environment : null, Ie = R === null ? _.outputColorSpace : R.isXRRenderTarget === !0 ? R.texture.colorSpace : pi, Be = (le.isMeshStandardMaterial ? H : y).get(le.envMap || ge), He = le.vertexColors === !0 && !!ue.attributes.color && ue.attributes.color.itemSize === 4, qe = !!ue.attributes.tangent && (!!le.normalMap || le.anisotropy > 0), Oe = !!ue.morphAttributes.position, Ze = !!ue.morphAttributes.normal, et = !!ue.morphAttributes.color;
      let tt = 0;
      le.toneMapped && (R === null || R.isXRRenderTarget === !0) && (tt = _.toneMapping);
      const vt = ue.morphAttributes.position || ue.morphAttributes.normal || ue.morphAttributes.color, Je = vt !== void 0 ? vt.length : 0, ke = me.get(le), Bt = p.state.lights;
      if (U === !0 && (G === !0 || w !== S)) {
        const Ut = w === S && le.id === E;
        ye.setState(le, w, Ut);
      }
      let Qe = !1;
      le.version === ke.__version ? (ke.needsLights && ke.lightsStateVersion !== Bt.state.version || ke.outputColorSpace !== Ie || J.isBatchedMesh && ke.batching === !1 || !J.isBatchedMesh && ke.batching === !0 || J.isBatchedMesh && ke.batchingColor === !0 && J.colorTexture === null || J.isBatchedMesh && ke.batchingColor === !1 && J.colorTexture !== null || J.isInstancedMesh && ke.instancing === !1 || !J.isInstancedMesh && ke.instancing === !0 || J.isSkinnedMesh && ke.skinning === !1 || !J.isSkinnedMesh && ke.skinning === !0 || J.isInstancedMesh && ke.instancingColor === !0 && J.instanceColor === null || J.isInstancedMesh && ke.instancingColor === !1 && J.instanceColor !== null || J.isInstancedMesh && ke.instancingMorph === !0 && J.morphTexture === null || J.isInstancedMesh && ke.instancingMorph === !1 && J.morphTexture !== null || ke.envMap !== Be || le.fog === !0 && ke.fog !== we || ke.numClippingPlanes !== void 0 && (ke.numClippingPlanes !== ye.numPlanes || ke.numIntersection !== ye.numIntersection) || ke.vertexAlphas !== He || ke.vertexTangents !== qe || ke.morphTargets !== Oe || ke.morphNormals !== Ze || ke.morphColors !== et || ke.toneMapping !== tt || ke.morphTargetsCount !== Je) && (Qe = !0) : (Qe = !0, ke.__version = le.version);
      let _t = ke.currentProgram;
      Qe === !0 && (_t = Ht(le, Q, J));
      let rn = !1, ut = !1, on = !1;
      const nt = _t.getUniforms(), Pt = ke.uniforms;
      if (te.useProgram(_t.program) && (rn = !0, ut = !0, on = !0), le.id !== E && (E = le.id, ut = !0), rn || S !== w) {
        te.buffers.depth.getReversed() ? (I.copy(w.projectionMatrix), wl(I), Cl(I), nt.setValue(P, "projectionMatrix", I)) : nt.setValue(P, "projectionMatrix", w.projectionMatrix), nt.setValue(P, "viewMatrix", w.matrixWorldInverse);
        const kt = nt.map.cameraPosition;
        kt !== void 0 && kt.setValue(P, re.setFromMatrixPosition(w.matrixWorld)), ve.logarithmicDepthBuffer && nt.setValue(
          P,
          "logDepthBufFC",
          2 / (Math.log(w.far + 1) / Math.LN2)
        ), (le.isMeshPhongMaterial || le.isMeshToonMaterial || le.isMeshLambertMaterial || le.isMeshBasicMaterial || le.isMeshStandardMaterial || le.isShaderMaterial) && nt.setValue(P, "isOrthographic", w.isOrthographicCamera === !0), S !== w && (S = w, ut = !0, on = !0);
      }
      if (J.isSkinnedMesh) {
        nt.setOptional(P, J, "bindMatrix"), nt.setOptional(P, J, "bindMatrixInverse");
        const Ut = J.skeleton;
        Ut && (Ut.boneTexture === null && Ut.computeBoneTexture(), nt.setValue(P, "boneTexture", Ut.boneTexture, M));
      }
      J.isBatchedMesh && (nt.setOptional(P, J, "batchingTexture"), nt.setValue(P, "batchingTexture", J._matricesTexture, M), nt.setOptional(P, J, "batchingIdTexture"), nt.setValue(P, "batchingIdTexture", J._indirectTexture, M), nt.setOptional(P, J, "batchingColorTexture"), J._colorsTexture !== null && nt.setValue(P, "batchingColorTexture", J._colorsTexture, M));
      const Mt = ue.morphAttributes;
      if ((Mt.position !== void 0 || Mt.normal !== void 0 || Mt.color !== void 0) && Ue.update(J, ue, _t), (ut || ke.receiveShadow !== J.receiveShadow) && (ke.receiveShadow = J.receiveShadow, nt.setValue(P, "receiveShadow", J.receiveShadow)), le.isMeshGouraudMaterial && le.envMap !== null && (Pt.envMap.value = Be, Pt.flipEnvMap.value = Be.isCubeTexture && Be.isRenderTargetTexture === !1 ? -1 : 1), le.isMeshStandardMaterial && le.envMap === null && Q.environment !== null && (Pt.envMapIntensity.value = Q.environmentIntensity), ut && (nt.setValue(P, "toneMappingExposure", _.toneMappingExposure), ke.needsLights && ji(Pt, on), we && le.fog === !0 && de.refreshFogUniforms(Pt, we), de.refreshMaterialUniforms(Pt, le, q, ne, p.state.transmissionRenderTarget[w.id]), Dr.upload(P, Si(ke), Pt, M)), le.isShaderMaterial && le.uniformsNeedUpdate === !0 && (Dr.upload(P, Si(ke), Pt, M), le.uniformsNeedUpdate = !1), le.isSpriteMaterial && nt.setValue(P, "center", J.center), nt.setValue(P, "modelViewMatrix", J.modelViewMatrix), nt.setValue(P, "normalMatrix", J.normalMatrix), nt.setValue(P, "modelMatrix", J.matrixWorld), le.isShaderMaterial || le.isRawShaderMaterial) {
        const Ut = le.uniformsGroups;
        for (let kt = 0, Dt = Ut.length; kt < Dt; kt++) {
          const yi = Ut[kt];
          X.update(yi, _t), X.bind(yi, _t);
        }
      }
      return _t;
    }
    function ji(w, Q) {
      w.ambientLightColor.needsUpdate = Q, w.lightProbe.needsUpdate = Q, w.directionalLights.needsUpdate = Q, w.directionalLightShadows.needsUpdate = Q, w.pointLights.needsUpdate = Q, w.pointLightShadows.needsUpdate = Q, w.spotLights.needsUpdate = Q, w.spotLightShadows.needsUpdate = Q, w.rectAreaLights.needsUpdate = Q, w.hemisphereLights.needsUpdate = Q;
    }
    function Hn(w) {
      return w.isMeshLambertMaterial || w.isMeshToonMaterial || w.isMeshPhongMaterial || w.isMeshStandardMaterial || w.isShadowMaterial || w.isShaderMaterial && w.lights === !0;
    }
    this.getActiveCubeFace = function() {
      return C;
    }, this.getActiveMipmapLevel = function() {
      return A;
    }, this.getRenderTarget = function() {
      return R;
    }, this.setRenderTargetTextures = function(w, Q, ue) {
      me.get(w.texture).__webglTexture = Q, me.get(w.depthTexture).__webglTexture = ue;
      const le = me.get(w);
      le.__hasExternalTextures = !0, le.__autoAllocateDepthBuffer = ue === void 0, le.__autoAllocateDepthBuffer || ae.has("WEBGL_multisampled_render_to_texture") === !0 && (console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"), le.__useRenderToTexture = !1);
    }, this.setRenderTargetFramebuffer = function(w, Q) {
      const ue = me.get(w);
      ue.__webglFramebuffer = Q, ue.__useDefaultFramebuffer = Q === void 0;
    }, this.setRenderTarget = function(w, Q = 0, ue = 0) {
      R = w, C = Q, A = ue;
      let le = !0, J = null, we = !1, ge = !1;
      if (w) {
        const Be = me.get(w);
        if (Be.__useDefaultFramebuffer !== void 0)
          te.bindFramebuffer(P.FRAMEBUFFER, null), le = !1;
        else if (Be.__webglFramebuffer === void 0)
          M.setupRenderTarget(w);
        else if (Be.__hasExternalTextures)
          M.rebindTextures(w, me.get(w.texture).__webglTexture, me.get(w.depthTexture).__webglTexture);
        else if (w.depthBuffer) {
          const Oe = w.depthTexture;
          if (Be.__boundDepthTexture !== Oe) {
            if (Oe !== null && me.has(Oe) && (w.width !== Oe.image.width || w.height !== Oe.image.height))
              throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");
            M.setupDepthRenderbuffer(w);
          }
        }
        const He = w.texture;
        (He.isData3DTexture || He.isDataArrayTexture || He.isCompressedArrayTexture) && (ge = !0);
        const qe = me.get(w).__webglFramebuffer;
        w.isWebGLCubeRenderTarget ? (Array.isArray(qe[Q]) ? J = qe[Q][ue] : J = qe[Q], we = !0) : w.samples > 0 && M.useMultisampledRTT(w) === !1 ? J = me.get(w).__webglMultisampledFramebuffer : Array.isArray(qe) ? J = qe[ue] : J = qe, F.copy(w.viewport), L.copy(w.scissor), B = w.scissorTest;
      } else
        F.copy(N).multiplyScalar(q).floor(), L.copy(Y).multiplyScalar(q).floor(), B = ie;
      if (te.bindFramebuffer(P.FRAMEBUFFER, J) && le && te.drawBuffers(w, J), te.viewport(F), te.scissor(L), te.setScissorTest(B), we) {
        const Be = me.get(w.texture);
        P.framebufferTexture2D(P.FRAMEBUFFER, P.COLOR_ATTACHMENT0, P.TEXTURE_CUBE_MAP_POSITIVE_X + Q, Be.__webglTexture, ue);
      } else if (ge) {
        const Be = me.get(w.texture), He = Q || 0;
        P.framebufferTextureLayer(P.FRAMEBUFFER, P.COLOR_ATTACHMENT0, Be.__webglTexture, ue || 0, He);
      }
      E = -1;
    }, this.readRenderTargetPixels = function(w, Q, ue, le, J, we, ge) {
      if (!(w && w.isWebGLRenderTarget)) {
        console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");
        return;
      }
      let Ie = me.get(w).__webglFramebuffer;
      if (w.isWebGLCubeRenderTarget && ge !== void 0 && (Ie = Ie[ge]), Ie) {
        te.bindFramebuffer(P.FRAMEBUFFER, Ie);
        try {
          const Be = w.texture, He = Be.format, qe = Be.type;
          if (!ve.textureFormatReadable(He)) {
            console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");
            return;
          }
          if (!ve.textureTypeReadable(qe)) {
            console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");
            return;
          }
          Q >= 0 && Q <= w.width - le && ue >= 0 && ue <= w.height - J && P.readPixels(Q, ue, le, J, Fe.convert(He), Fe.convert(qe), we);
        } finally {
          const Be = R !== null ? me.get(R).__webglFramebuffer : null;
          te.bindFramebuffer(P.FRAMEBUFFER, Be);
        }
      }
    }, this.readRenderTargetPixelsAsync = async function(w, Q, ue, le, J, we, ge) {
      if (!(w && w.isWebGLRenderTarget))
        throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");
      let Ie = me.get(w).__webglFramebuffer;
      if (w.isWebGLCubeRenderTarget && ge !== void 0 && (Ie = Ie[ge]), Ie) {
        const Be = w.texture, He = Be.format, qe = Be.type;
        if (!ve.textureFormatReadable(He))
          throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");
        if (!ve.textureTypeReadable(qe))
          throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");
        if (Q >= 0 && Q <= w.width - le && ue >= 0 && ue <= w.height - J) {
          te.bindFramebuffer(P.FRAMEBUFFER, Ie);
          const Oe = P.createBuffer();
          P.bindBuffer(P.PIXEL_PACK_BUFFER, Oe), P.bufferData(P.PIXEL_PACK_BUFFER, we.byteLength, P.STREAM_READ), P.readPixels(Q, ue, le, J, Fe.convert(He), Fe.convert(qe), 0);
          const Ze = R !== null ? me.get(R).__webglFramebuffer : null;
          te.bindFramebuffer(P.FRAMEBUFFER, Ze);
          const et = P.fenceSync(P.SYNC_GPU_COMMANDS_COMPLETE, 0);
          return P.flush(), await Al(P, et, 4), P.bindBuffer(P.PIXEL_PACK_BUFFER, Oe), P.getBufferSubData(P.PIXEL_PACK_BUFFER, 0, we), P.deleteBuffer(Oe), P.deleteSync(et), we;
        } else
          throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.");
      }
    }, this.copyFramebufferToTexture = function(w, Q = null, ue = 0) {
      w.isTexture !== !0 && (Ni("WebGLRenderer: copyFramebufferToTexture function signature has changed."), Q = arguments[0] || null, w = arguments[1]);
      const le = Math.pow(2, -ue), J = Math.floor(w.image.width * le), we = Math.floor(w.image.height * le), ge = Q !== null ? Q.x : 0, Ie = Q !== null ? Q.y : 0;
      M.setTexture2D(w, 0), P.copyTexSubImage2D(P.TEXTURE_2D, ue, 0, 0, ge, Ie, J, we), te.unbindTexture();
    }, this.copyTextureToTexture = function(w, Q, ue = null, le = null, J = 0) {
      w.isTexture !== !0 && (Ni("WebGLRenderer: copyTextureToTexture function signature has changed."), le = arguments[0] || null, w = arguments[1], Q = arguments[2], J = arguments[3] || 0, ue = null);
      let we, ge, Ie, Be, He, qe, Oe, Ze, et;
      const tt = w.isCompressedTexture ? w.mipmaps[J] : w.image;
      ue !== null ? (we = ue.max.x - ue.min.x, ge = ue.max.y - ue.min.y, Ie = ue.isBox3 ? ue.max.z - ue.min.z : 1, Be = ue.min.x, He = ue.min.y, qe = ue.isBox3 ? ue.min.z : 0) : (we = tt.width, ge = tt.height, Ie = tt.depth || 1, Be = 0, He = 0, qe = 0), le !== null ? (Oe = le.x, Ze = le.y, et = le.z) : (Oe = 0, Ze = 0, et = 0);
      const vt = Fe.convert(Q.format), Je = Fe.convert(Q.type);
      let ke;
      Q.isData3DTexture ? (M.setTexture3D(Q, 0), ke = P.TEXTURE_3D) : Q.isDataArrayTexture || Q.isCompressedArrayTexture ? (M.setTexture2DArray(Q, 0), ke = P.TEXTURE_2D_ARRAY) : (M.setTexture2D(Q, 0), ke = P.TEXTURE_2D), P.pixelStorei(P.UNPACK_FLIP_Y_WEBGL, Q.flipY), P.pixelStorei(P.UNPACK_PREMULTIPLY_ALPHA_WEBGL, Q.premultiplyAlpha), P.pixelStorei(P.UNPACK_ALIGNMENT, Q.unpackAlignment);
      const Bt = P.getParameter(P.UNPACK_ROW_LENGTH), Qe = P.getParameter(P.UNPACK_IMAGE_HEIGHT), _t = P.getParameter(P.UNPACK_SKIP_PIXELS), rn = P.getParameter(P.UNPACK_SKIP_ROWS), ut = P.getParameter(P.UNPACK_SKIP_IMAGES);
      P.pixelStorei(P.UNPACK_ROW_LENGTH, tt.width), P.pixelStorei(P.UNPACK_IMAGE_HEIGHT, tt.height), P.pixelStorei(P.UNPACK_SKIP_PIXELS, Be), P.pixelStorei(P.UNPACK_SKIP_ROWS, He), P.pixelStorei(P.UNPACK_SKIP_IMAGES, qe);
      const on = w.isDataArrayTexture || w.isData3DTexture, nt = Q.isDataArrayTexture || Q.isData3DTexture;
      if (w.isRenderTargetTexture || w.isDepthTexture) {
        const Pt = me.get(w), Mt = me.get(Q), Ut = me.get(Pt.__renderTarget), kt = me.get(Mt.__renderTarget);
        te.bindFramebuffer(P.READ_FRAMEBUFFER, Ut.__webglFramebuffer), te.bindFramebuffer(P.DRAW_FRAMEBUFFER, kt.__webglFramebuffer);
        for (let Dt = 0; Dt < Ie; Dt++)
          on && P.framebufferTextureLayer(P.READ_FRAMEBUFFER, P.COLOR_ATTACHMENT0, me.get(w).__webglTexture, J, qe + Dt), w.isDepthTexture ? (nt && P.framebufferTextureLayer(P.DRAW_FRAMEBUFFER, P.COLOR_ATTACHMENT0, me.get(Q).__webglTexture, J, et + Dt), P.blitFramebuffer(Be, He, we, ge, Oe, Ze, we, ge, P.DEPTH_BUFFER_BIT, P.NEAREST)) : nt ? P.copyTexSubImage3D(ke, J, Oe, Ze, et + Dt, Be, He, we, ge) : P.copyTexSubImage2D(ke, J, Oe, Ze, et + Dt, Be, He, we, ge);
        te.bindFramebuffer(P.READ_FRAMEBUFFER, null), te.bindFramebuffer(P.DRAW_FRAMEBUFFER, null);
      } else
        nt ? w.isDataTexture || w.isData3DTexture ? P.texSubImage3D(ke, J, Oe, Ze, et, we, ge, Ie, vt, Je, tt.data) : Q.isCompressedArrayTexture ? P.compressedTexSubImage3D(ke, J, Oe, Ze, et, we, ge, Ie, vt, tt.data) : P.texSubImage3D(ke, J, Oe, Ze, et, we, ge, Ie, vt, Je, tt) : w.isDataTexture ? P.texSubImage2D(P.TEXTURE_2D, J, Oe, Ze, we, ge, vt, Je, tt.data) : w.isCompressedTexture ? P.compressedTexSubImage2D(P.TEXTURE_2D, J, Oe, Ze, tt.width, tt.height, vt, tt.data) : P.texSubImage2D(P.TEXTURE_2D, J, Oe, Ze, we, ge, vt, Je, tt);
      P.pixelStorei(P.UNPACK_ROW_LENGTH, Bt), P.pixelStorei(P.UNPACK_IMAGE_HEIGHT, Qe), P.pixelStorei(P.UNPACK_SKIP_PIXELS, _t), P.pixelStorei(P.UNPACK_SKIP_ROWS, rn), P.pixelStorei(P.UNPACK_SKIP_IMAGES, ut), J === 0 && Q.generateMipmaps && P.generateMipmap(ke), te.unbindTexture();
    }, this.copyTextureToTexture3D = function(w, Q, ue = null, le = null, J = 0) {
      return w.isTexture !== !0 && (Ni("WebGLRenderer: copyTextureToTexture3D function signature has changed."), ue = arguments[0] || null, le = arguments[1] || null, w = arguments[2], Q = arguments[3], J = arguments[4] || 0), Ni('WebGLRenderer: copyTextureToTexture3D function has been deprecated. Use "copyTextureToTexture" instead.'), this.copyTextureToTexture(w, Q, ue, le, J);
    }, this.initRenderTarget = function(w) {
      me.get(w).__webglFramebuffer === void 0 && M.setupRenderTarget(w);
    }, this.initTexture = function(w) {
      w.isCubeTexture ? M.setTextureCube(w, 0) : w.isData3DTexture ? M.setTexture3D(w, 0) : w.isDataArrayTexture || w.isCompressedArrayTexture ? M.setTexture2DArray(w, 0) : M.setTexture2D(w, 0), te.unbindTexture();
    }, this.resetState = function() {
      C = 0, A = 0, R = null, te.reset(), je.reset();
    }, typeof __THREE_DEVTOOLS__ < "u" && __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe", { detail: this }));
  }
  get coordinateSystem() {
    return 2e3;
  }
  get outputColorSpace() {
    return this._outputColorSpace;
  }
  set outputColorSpace(e) {
    this._outputColorSpace = e;
    const t = this.getContext();
    t.drawingBufferColorspace = $e._getDrawingBufferColorSpace(e), t.unpackColorSpace = $e._getUnpackColorSpace();
  }
}
class Nd extends gt {
  constructor() {
    super(), this.isScene = !0, this.type = "Scene", this.background = null, this.environment = null, this.fog = null, this.backgroundBlurriness = 0, this.backgroundIntensity = 1, this.backgroundRotation = new mn(), this.environmentIntensity = 1, this.environmentRotation = new mn(), this.overrideMaterial = null, typeof __THREE_DEVTOOLS__ < "u" && __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe", { detail: this }));
  }
  copy(e, t) {
    return super.copy(e, t), e.background !== null && (this.background = e.background.clone()), e.environment !== null && (this.environment = e.environment.clone()), e.fog !== null && (this.fog = e.fog.clone()), this.backgroundBlurriness = e.backgroundBlurriness, this.backgroundIntensity = e.backgroundIntensity, this.backgroundRotation.copy(e.backgroundRotation), this.environmentIntensity = e.environmentIntensity, this.environmentRotation.copy(e.environmentRotation), e.overrideMaterial !== null && (this.overrideMaterial = e.overrideMaterial.clone()), this.matrixAutoUpdate = e.matrixAutoUpdate, this;
  }
  toJSON(e) {
    const t = super.toJSON(e);
    return this.fog !== null && (t.object.fog = this.fog.toJSON()), this.backgroundBlurriness > 0 && (t.object.backgroundBlurriness = this.backgroundBlurriness), this.backgroundIntensity !== 1 && (t.object.backgroundIntensity = this.backgroundIntensity), t.object.backgroundRotation = this.backgroundRotation.toArray(), this.environmentIntensity !== 1 && (t.object.environmentIntensity = this.environmentIntensity), t.object.environmentRotation = this.environmentRotation.toArray(), t;
  }
}
class Od extends en {
  constructor(e, t, r, n = 1) {
    super(e, t, r), this.isInstancedBufferAttribute = !0, this.meshPerAttribute = n;
  }
  copy(e) {
    return super.copy(e), this.meshPerAttribute = e.meshPerAttribute, this;
  }
  toJSON() {
    const e = super.toJSON();
    return e.meshPerAttribute = this.meshPerAttribute, e.isInstancedBufferAttribute = !0, e;
  }
}
class li extends vi {
  static get type() {
    return "LineBasicMaterial";
  }
  constructor(e) {
    super(), this.isLineBasicMaterial = !0, this.color = new Ke(16777215), this.map = null, this.linewidth = 1, this.linecap = "round", this.linejoin = "round", this.fog = !0, this.setValues(e);
  }
  copy(e) {
    return super.copy(e), this.color.copy(e.color), this.map = e.map, this.linewidth = e.linewidth, this.linecap = e.linecap, this.linejoin = e.linejoin, this.fog = e.fog, this;
  }
}
const Or = /* @__PURE__ */ new j(), Br = /* @__PURE__ */ new j(), uo = /* @__PURE__ */ new st(), Fi = /* @__PURE__ */ new Ja(), Mr = /* @__PURE__ */ new gi(), Ua = /* @__PURE__ */ new j(), ho = /* @__PURE__ */ new j();
class Er extends gt {
  constructor(e = new St(), t = new li()) {
    super(), this.isLine = !0, this.type = "Line", this.geometry = e, this.material = t, this.updateMorphTargets();
  }
  copy(e, t) {
    return super.copy(e, t), this.material = Array.isArray(e.material) ? e.material.slice() : e.material, this.geometry = e.geometry, this;
  }
  computeLineDistances() {
    const e = this.geometry;
    if (e.index === null) {
      const t = e.attributes.position, r = [0];
      for (let n = 1, i = t.count; n < i; n++)
        Or.fromBufferAttribute(t, n - 1), Br.fromBufferAttribute(t, n), r[n] = r[n - 1], r[n] += Or.distanceTo(Br);
      e.setAttribute("lineDistance", new tn(r, 1));
    } else
      console.warn("THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");
    return this;
  }
  raycast(e, t) {
    const r = this.geometry, n = this.matrixWorld, i = e.params.Line.threshold, s = r.drawRange;
    if (r.boundingSphere === null && r.computeBoundingSphere(), Mr.copy(r.boundingSphere), Mr.applyMatrix4(n), Mr.radius += i, e.ray.intersectsSphere(Mr) === !1) return;
    uo.copy(n).invert(), Fi.copy(e.ray).applyMatrix4(uo);
    const o = i / ((this.scale.x + this.scale.y + this.scale.z) / 3), l = o * o, c = this.isLineSegments ? 2 : 1, u = r.index, h = r.attributes.position;
    if (u !== null) {
      const d = Math.max(0, s.start), g = Math.min(u.count, s.start + s.count);
      for (let v = d, m = g - 1; v < m; v += c) {
        const p = u.getX(v), T = u.getX(v + 1), x = Tr(this, e, Fi, l, p, T);
        x && t.push(x);
      }
      if (this.isLineLoop) {
        const v = u.getX(g - 1), m = u.getX(d), p = Tr(this, e, Fi, l, v, m);
        p && t.push(p);
      }
    } else {
      const d = Math.max(0, s.start), g = Math.min(h.count, s.start + s.count);
      for (let v = d, m = g - 1; v < m; v += c) {
        const p = Tr(this, e, Fi, l, v, v + 1);
        p && t.push(p);
      }
      if (this.isLineLoop) {
        const v = Tr(this, e, Fi, l, g - 1, d);
        v && t.push(v);
      }
    }
  }
  updateMorphTargets() {
    const t = this.geometry.morphAttributes, r = Object.keys(t);
    if (r.length > 0) {
      const n = t[r[0]];
      if (n !== void 0) {
        this.morphTargetInfluences = [], this.morphTargetDictionary = {};
        for (let i = 0, s = n.length; i < s; i++) {
          const o = n[i].name || String(i);
          this.morphTargetInfluences.push(0), this.morphTargetDictionary[o] = i;
        }
      }
    }
  }
}
function Tr(a, e, t, r, n, i) {
  const s = a.geometry.attributes.position;
  if (Or.fromBufferAttribute(s, n), Br.fromBufferAttribute(s, i), t.distanceSqToSegment(Or, Br, Ua, ho) > r) return;
  Ua.applyMatrix4(a.matrixWorld);
  const l = e.ray.origin.distanceTo(Ua);
  if (!(l < e.near || l > e.far))
    return {
      distance: l,
      // What do we want? intersection point on the ray or on the segment??
      // point: raycaster.ray.at( distance ),
      point: ho.clone().applyMatrix4(a.matrixWorld),
      index: n,
      face: null,
      faceIndex: null,
      barycoord: null,
      object: a
    };
}
class tl extends vi {
  static get type() {
    return "PointsMaterial";
  }
  constructor(e) {
    super(), this.isPointsMaterial = !0, this.color = new Ke(16777215), this.map = null, this.alphaMap = null, this.size = 1, this.sizeAttenuation = !0, this.fog = !0, this.setValues(e);
  }
  copy(e) {
    return super.copy(e), this.color.copy(e.color), this.map = e.map, this.alphaMap = e.alphaMap, this.size = e.size, this.sizeAttenuation = e.sizeAttenuation, this.fog = e.fog, this;
  }
}
const fo = /* @__PURE__ */ new st(), za = /* @__PURE__ */ new Ja(), br = /* @__PURE__ */ new gi(), Ar = /* @__PURE__ */ new j();
class Bd extends gt {
  constructor(e = new St(), t = new tl()) {
    super(), this.isPoints = !0, this.type = "Points", this.geometry = e, this.material = t, this.updateMorphTargets();
  }
  copy(e, t) {
    return super.copy(e, t), this.material = Array.isArray(e.material) ? e.material.slice() : e.material, this.geometry = e.geometry, this;
  }
  raycast(e, t) {
    const r = this.geometry, n = this.matrixWorld, i = e.params.Points.threshold, s = r.drawRange;
    if (r.boundingSphere === null && r.computeBoundingSphere(), br.copy(r.boundingSphere), br.applyMatrix4(n), br.radius += i, e.ray.intersectsSphere(br) === !1) return;
    fo.copy(n).invert(), za.copy(e.ray).applyMatrix4(fo);
    const o = i / ((this.scale.x + this.scale.y + this.scale.z) / 3), l = o * o, c = r.index, f = r.attributes.position;
    if (c !== null) {
      const h = Math.max(0, s.start), d = Math.min(c.count, s.start + s.count);
      for (let g = h, v = d; g < v; g++) {
        const m = c.getX(g);
        Ar.fromBufferAttribute(f, m), po(Ar, m, l, n, e, t, this);
      }
    } else {
      const h = Math.max(0, s.start), d = Math.min(f.count, s.start + s.count);
      for (let g = h, v = d; g < v; g++)
        Ar.fromBufferAttribute(f, g), po(Ar, g, l, n, e, t, this);
    }
  }
  updateMorphTargets() {
    const t = this.geometry.morphAttributes, r = Object.keys(t);
    if (r.length > 0) {
      const n = t[r[0]];
      if (n !== void 0) {
        this.morphTargetInfluences = [], this.morphTargetDictionary = {};
        for (let i = 0, s = n.length; i < s; i++) {
          const o = n[i].name || String(i);
          this.morphTargetInfluences.push(0), this.morphTargetDictionary[o] = i;
        }
      }
    }
  }
}
function po(a, e, t, r, n, i, s) {
  const o = za.distanceSqToPoint(a);
  if (o < t) {
    const l = new j();
    za.closestPointToPoint(a, l), l.applyMatrix4(r);
    const c = n.ray.origin.distanceTo(l);
    if (c < n.near || c > n.far) return;
    i.push({
      distance: c,
      distanceToRay: Math.sqrt(o),
      point: l,
      index: e,
      face: null,
      faceIndex: null,
      barycoord: null,
      object: s
    });
  }
}
class sn {
  constructor() {
    this.type = "Curve", this.arcLengthDivisions = 200;
  }
  // Virtual base class method to overwrite and implement in subclasses
  //	- t [0 .. 1]
  getPoint() {
    return console.warn("THREE.Curve: .getPoint() not implemented."), null;
  }
  // Get point at relative position in curve according to arc length
  // - u [0 .. 1]
  getPointAt(e, t) {
    const r = this.getUtoTmapping(e);
    return this.getPoint(r, t);
  }
  // Get sequence of points using getPoint( t )
  getPoints(e = 5) {
    const t = [];
    for (let r = 0; r <= e; r++)
      t.push(this.getPoint(r / e));
    return t;
  }
  // Get sequence of points using getPointAt( u )
  getSpacedPoints(e = 5) {
    const t = [];
    for (let r = 0; r <= e; r++)
      t.push(this.getPointAt(r / e));
    return t;
  }
  // Get total curve arc length
  getLength() {
    const e = this.getLengths();
    return e[e.length - 1];
  }
  // Get list of cumulative segment lengths
  getLengths(e = this.arcLengthDivisions) {
    if (this.cacheArcLengths && this.cacheArcLengths.length === e + 1 && !this.needsUpdate)
      return this.cacheArcLengths;
    this.needsUpdate = !1;
    const t = [];
    let r, n = this.getPoint(0), i = 0;
    t.push(0);
    for (let s = 1; s <= e; s++)
      r = this.getPoint(s / e), i += r.distanceTo(n), t.push(i), n = r;
    return this.cacheArcLengths = t, t;
  }
  updateArcLengths() {
    this.needsUpdate = !0, this.getLengths();
  }
  // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  getUtoTmapping(e, t) {
    const r = this.getLengths();
    let n = 0;
    const i = r.length;
    let s;
    t ? s = t : s = e * r[i - 1];
    let o = 0, l = i - 1, c;
    for (; o <= l; )
      if (n = Math.floor(o + (l - o) / 2), c = r[n] - s, c < 0)
        o = n + 1;
      else if (c > 0)
        l = n - 1;
      else {
        l = n;
        break;
      }
    if (n = l, r[n] === s)
      return n / (i - 1);
    const u = r[n], h = r[n + 1] - u, d = (s - u) / h;
    return (n + d) / (i - 1);
  }
  // Returns a unit vector tangent at t
  // In case any sub curve does not implement its tangent derivation,
  // 2 points a small delta apart will be used to find its gradient
  // which seems to give a reasonable approximation
  getTangent(e, t) {
    let n = e - 1e-4, i = e + 1e-4;
    n < 0 && (n = 0), i > 1 && (i = 1);
    const s = this.getPoint(n), o = this.getPoint(i), l = t || (s.isVector2 ? new Ce() : new j());
    return l.copy(o).sub(s).normalize(), l;
  }
  getTangentAt(e, t) {
    const r = this.getUtoTmapping(e);
    return this.getTangent(r, t);
  }
  computeFrenetFrames(e, t) {
    const r = new j(), n = [], i = [], s = [], o = new j(), l = new st();
    for (let d = 0; d <= e; d++) {
      const g = d / e;
      n[d] = this.getTangentAt(g, new j());
    }
    i[0] = new j(), s[0] = new j();
    let c = Number.MAX_VALUE;
    const u = Math.abs(n[0].x), f = Math.abs(n[0].y), h = Math.abs(n[0].z);
    u <= c && (c = u, r.set(1, 0, 0)), f <= c && (c = f, r.set(0, 1, 0)), h <= c && r.set(0, 0, 1), o.crossVectors(n[0], r).normalize(), i[0].crossVectors(n[0], o), s[0].crossVectors(n[0], i[0]);
    for (let d = 1; d <= e; d++) {
      if (i[d] = i[d - 1].clone(), s[d] = s[d - 1].clone(), o.crossVectors(n[d - 1], n[d]), o.length() > Number.EPSILON) {
        o.normalize();
        const g = Math.acos(bt(n[d - 1].dot(n[d]), -1, 1));
        i[d].applyMatrix4(l.makeRotationAxis(o, g));
      }
      s[d].crossVectors(n[d], i[d]);
    }
    if (t === !0) {
      let d = Math.acos(bt(i[0].dot(i[e]), -1, 1));
      d /= e, n[0].dot(o.crossVectors(i[0], i[e])) > 0 && (d = -d);
      for (let g = 1; g <= e; g++)
        i[g].applyMatrix4(l.makeRotationAxis(n[g], d * g)), s[g].crossVectors(n[g], i[g]);
    }
    return {
      tangents: n,
      normals: i,
      binormals: s
    };
  }
  clone() {
    return new this.constructor().copy(this);
  }
  copy(e) {
    return this.arcLengthDivisions = e.arcLengthDivisions, this;
  }
  toJSON() {
    const e = {
      metadata: {
        version: 4.6,
        type: "Curve",
        generator: "Curve.toJSON"
      }
    };
    return e.arcLengthDivisions = this.arcLengthDivisions, e.type = this.type, e;
  }
  fromJSON(e) {
    return this.arcLengthDivisions = e.arcLengthDivisions, this;
  }
}
class zr extends sn {
  constructor(e = 0, t = 0, r = 1, n = 1, i = 0, s = Math.PI * 2, o = !1, l = 0) {
    super(), this.isEllipseCurve = !0, this.type = "EllipseCurve", this.aX = e, this.aY = t, this.xRadius = r, this.yRadius = n, this.aStartAngle = i, this.aEndAngle = s, this.aClockwise = o, this.aRotation = l;
  }
  getPoint(e, t = new Ce()) {
    const r = t, n = Math.PI * 2;
    let i = this.aEndAngle - this.aStartAngle;
    const s = Math.abs(i) < Number.EPSILON;
    for (; i < 0; ) i += n;
    for (; i > n; ) i -= n;
    i < Number.EPSILON && (s ? i = 0 : i = n), this.aClockwise === !0 && !s && (i === n ? i = -n : i = i - n);
    const o = this.aStartAngle + e * i;
    let l = this.aX + this.xRadius * Math.cos(o), c = this.aY + this.yRadius * Math.sin(o);
    if (this.aRotation !== 0) {
      const u = Math.cos(this.aRotation), f = Math.sin(this.aRotation), h = l - this.aX, d = c - this.aY;
      l = h * u - d * f + this.aX, c = h * f + d * u + this.aY;
    }
    return r.set(l, c);
  }
  copy(e) {
    return super.copy(e), this.aX = e.aX, this.aY = e.aY, this.xRadius = e.xRadius, this.yRadius = e.yRadius, this.aStartAngle = e.aStartAngle, this.aEndAngle = e.aEndAngle, this.aClockwise = e.aClockwise, this.aRotation = e.aRotation, this;
  }
  toJSON() {
    const e = super.toJSON();
    return e.aX = this.aX, e.aY = this.aY, e.xRadius = this.xRadius, e.yRadius = this.yRadius, e.aStartAngle = this.aStartAngle, e.aEndAngle = this.aEndAngle, e.aClockwise = this.aClockwise, e.aRotation = this.aRotation, e;
  }
  fromJSON(e) {
    return super.fromJSON(e), this.aX = e.aX, this.aY = e.aY, this.xRadius = e.xRadius, this.yRadius = e.yRadius, this.aStartAngle = e.aStartAngle, this.aEndAngle = e.aEndAngle, this.aClockwise = e.aClockwise, this.aRotation = e.aRotation, this;
  }
}
class nl extends zr {
  constructor(e, t, r, n, i, s) {
    super(e, t, r, r, n, i, s), this.isArcCurve = !0, this.type = "ArcCurve";
  }
}
function es() {
  let a = 0, e = 0, t = 0, r = 0;
  function n(i, s, o, l) {
    a = i, e = o, t = -3 * i + 3 * s - 2 * o - l, r = 2 * i - 2 * s + o + l;
  }
  return {
    initCatmullRom: function(i, s, o, l, c) {
      n(s, o, c * (o - i), c * (l - s));
    },
    initNonuniformCatmullRom: function(i, s, o, l, c, u, f) {
      let h = (s - i) / c - (o - i) / (c + u) + (o - s) / u, d = (o - s) / u - (l - s) / (u + f) + (l - o) / f;
      h *= u, d *= u, n(s, o, h, d);
    },
    calc: function(i) {
      const s = i * i, o = s * i;
      return a + e * i + t * s + r * o;
    }
  };
}
const wr = /* @__PURE__ */ new j(), Da = /* @__PURE__ */ new es(), La = /* @__PURE__ */ new es(), Fa = /* @__PURE__ */ new es();
class kd extends sn {
  constructor(e = [], t = !1, r = "centripetal", n = 0.5) {
    super(), this.isCatmullRomCurve3 = !0, this.type = "CatmullRomCurve3", this.points = e, this.closed = t, this.curveType = r, this.tension = n;
  }
  getPoint(e, t = new j()) {
    const r = t, n = this.points, i = n.length, s = (i - (this.closed ? 0 : 1)) * e;
    let o = Math.floor(s), l = s - o;
    this.closed ? o += o > 0 ? 0 : (Math.floor(Math.abs(o) / i) + 1) * i : l === 0 && o === i - 1 && (o = i - 2, l = 1);
    let c, u;
    this.closed || o > 0 ? c = n[(o - 1) % i] : (wr.subVectors(n[0], n[1]).add(n[0]), c = wr);
    const f = n[o % i], h = n[(o + 1) % i];
    if (this.closed || o + 2 < i ? u = n[(o + 2) % i] : (wr.subVectors(n[i - 1], n[i - 2]).add(n[i - 1]), u = wr), this.curveType === "centripetal" || this.curveType === "chordal") {
      const d = this.curveType === "chordal" ? 0.5 : 0.25;
      let g = Math.pow(c.distanceToSquared(f), d), v = Math.pow(f.distanceToSquared(h), d), m = Math.pow(h.distanceToSquared(u), d);
      v < 1e-4 && (v = 1), g < 1e-4 && (g = v), m < 1e-4 && (m = v), Da.initNonuniformCatmullRom(c.x, f.x, h.x, u.x, g, v, m), La.initNonuniformCatmullRom(c.y, f.y, h.y, u.y, g, v, m), Fa.initNonuniformCatmullRom(c.z, f.z, h.z, u.z, g, v, m);
    } else this.curveType === "catmullrom" && (Da.initCatmullRom(c.x, f.x, h.x, u.x, this.tension), La.initCatmullRom(c.y, f.y, h.y, u.y, this.tension), Fa.initCatmullRom(c.z, f.z, h.z, u.z, this.tension));
    return r.set(
      Da.calc(l),
      La.calc(l),
      Fa.calc(l)
    ), r;
  }
  copy(e) {
    super.copy(e), this.points = [];
    for (let t = 0, r = e.points.length; t < r; t++) {
      const n = e.points[t];
      this.points.push(n.clone());
    }
    return this.closed = e.closed, this.curveType = e.curveType, this.tension = e.tension, this;
  }
  toJSON() {
    const e = super.toJSON();
    e.points = [];
    for (let t = 0, r = this.points.length; t < r; t++) {
      const n = this.points[t];
      e.points.push(n.toArray());
    }
    return e.closed = this.closed, e.curveType = this.curveType, e.tension = this.tension, e;
  }
  fromJSON(e) {
    super.fromJSON(e), this.points = [];
    for (let t = 0, r = e.points.length; t < r; t++) {
      const n = e.points[t];
      this.points.push(new j().fromArray(n));
    }
    return this.closed = e.closed, this.curveType = e.curveType, this.tension = e.tension, this;
  }
}
function mo(a, e, t, r, n) {
  const i = (r - e) * 0.5, s = (n - t) * 0.5, o = a * a, l = a * o;
  return (2 * t - 2 * r + i + s) * l + (-3 * t + 3 * r - 2 * i - s) * o + i * a + t;
}
function Gd(a, e) {
  const t = 1 - a;
  return t * t * e;
}
function zd(a, e) {
  return 2 * (1 - a) * a * e;
}
function Vd(a, e) {
  return a * a * e;
}
function Bi(a, e, t, r) {
  return Gd(a, e) + zd(a, t) + Vd(a, r);
}
function Hd(a, e) {
  const t = 1 - a;
  return t * t * t * e;
}
function Wd(a, e) {
  const t = 1 - a;
  return 3 * t * t * a * e;
}
function Xd(a, e) {
  return 3 * (1 - a) * a * a * e;
}
function qd(a, e) {
  return a * a * a * e;
}
function ki(a, e, t, r, n) {
  return Hd(a, e) + Wd(a, t) + Xd(a, r) + qd(a, n);
}
class il extends sn {
  constructor(e = new Ce(), t = new Ce(), r = new Ce(), n = new Ce()) {
    super(), this.isCubicBezierCurve = !0, this.type = "CubicBezierCurve", this.v0 = e, this.v1 = t, this.v2 = r, this.v3 = n;
  }
  getPoint(e, t = new Ce()) {
    const r = t, n = this.v0, i = this.v1, s = this.v2, o = this.v3;
    return r.set(
      ki(e, n.x, i.x, s.x, o.x),
      ki(e, n.y, i.y, s.y, o.y)
    ), r;
  }
  copy(e) {
    return super.copy(e), this.v0.copy(e.v0), this.v1.copy(e.v1), this.v2.copy(e.v2), this.v3.copy(e.v3), this;
  }
  toJSON() {
    const e = super.toJSON();
    return e.v0 = this.v0.toArray(), e.v1 = this.v1.toArray(), e.v2 = this.v2.toArray(), e.v3 = this.v3.toArray(), e;
  }
  fromJSON(e) {
    return super.fromJSON(e), this.v0.fromArray(e.v0), this.v1.fromArray(e.v1), this.v2.fromArray(e.v2), this.v3.fromArray(e.v3), this;
  }
}
class Yd extends sn {
  constructor(e = new j(), t = new j(), r = new j(), n = new j()) {
    super(), this.isCubicBezierCurve3 = !0, this.type = "CubicBezierCurve3", this.v0 = e, this.v1 = t, this.v2 = r, this.v3 = n;
  }
  getPoint(e, t = new j()) {
    const r = t, n = this.v0, i = this.v1, s = this.v2, o = this.v3;
    return r.set(
      ki(e, n.x, i.x, s.x, o.x),
      ki(e, n.y, i.y, s.y, o.y),
      ki(e, n.z, i.z, s.z, o.z)
    ), r;
  }
  copy(e) {
    return super.copy(e), this.v0.copy(e.v0), this.v1.copy(e.v1), this.v2.copy(e.v2), this.v3.copy(e.v3), this;
  }
  toJSON() {
    const e = super.toJSON();
    return e.v0 = this.v0.toArray(), e.v1 = this.v1.toArray(), e.v2 = this.v2.toArray(), e.v3 = this.v3.toArray(), e;
  }
  fromJSON(e) {
    return super.fromJSON(e), this.v0.fromArray(e.v0), this.v1.fromArray(e.v1), this.v2.fromArray(e.v2), this.v3.fromArray(e.v3), this;
  }
}
class rl extends sn {
  constructor(e = new Ce(), t = new Ce()) {
    super(), this.isLineCurve = !0, this.type = "LineCurve", this.v1 = e, this.v2 = t;
  }
  getPoint(e, t = new Ce()) {
    const r = t;
    return e === 1 ? r.copy(this.v2) : (r.copy(this.v2).sub(this.v1), r.multiplyScalar(e).add(this.v1)), r;
  }
  // Line curve is linear, so we can overwrite default getPointAt
  getPointAt(e, t) {
    return this.getPoint(e, t);
  }
  getTangent(e, t = new Ce()) {
    return t.subVectors(this.v2, this.v1).normalize();
  }
  getTangentAt(e, t) {
    return this.getTangent(e, t);
  }
  copy(e) {
    return super.copy(e), this.v1.copy(e.v1), this.v2.copy(e.v2), this;
  }
  toJSON() {
    const e = super.toJSON();
    return e.v1 = this.v1.toArray(), e.v2 = this.v2.toArray(), e;
  }
  fromJSON(e) {
    return super.fromJSON(e), this.v1.fromArray(e.v1), this.v2.fromArray(e.v2), this;
  }
}
class jd extends sn {
  constructor(e = new j(), t = new j()) {
    super(), this.isLineCurve3 = !0, this.type = "LineCurve3", this.v1 = e, this.v2 = t;
  }
  getPoint(e, t = new j()) {
    const r = t;
    return e === 1 ? r.copy(this.v2) : (r.copy(this.v2).sub(this.v1), r.multiplyScalar(e).add(this.v1)), r;
  }
  // Line curve is linear, so we can overwrite default getPointAt
  getPointAt(e, t) {
    return this.getPoint(e, t);
  }
  getTangent(e, t = new j()) {
    return t.subVectors(this.v2, this.v1).normalize();
  }
  getTangentAt(e, t) {
    return this.getTangent(e, t);
  }
  copy(e) {
    return super.copy(e), this.v1.copy(e.v1), this.v2.copy(e.v2), this;
  }
  toJSON() {
    const e = super.toJSON();
    return e.v1 = this.v1.toArray(), e.v2 = this.v2.toArray(), e;
  }
  fromJSON(e) {
    return super.fromJSON(e), this.v1.fromArray(e.v1), this.v2.fromArray(e.v2), this;
  }
}
class al extends sn {
  constructor(e = new Ce(), t = new Ce(), r = new Ce()) {
    super(), this.isQuadraticBezierCurve = !0, this.type = "QuadraticBezierCurve", this.v0 = e, this.v1 = t, this.v2 = r;
  }
  getPoint(e, t = new Ce()) {
    const r = t, n = this.v0, i = this.v1, s = this.v2;
    return r.set(
      Bi(e, n.x, i.x, s.x),
      Bi(e, n.y, i.y, s.y)
    ), r;
  }
  copy(e) {
    return super.copy(e), this.v0.copy(e.v0), this.v1.copy(e.v1), this.v2.copy(e.v2), this;
  }
  toJSON() {
    const e = super.toJSON();
    return e.v0 = this.v0.toArray(), e.v1 = this.v1.toArray(), e.v2 = this.v2.toArray(), e;
  }
  fromJSON(e) {
    return super.fromJSON(e), this.v0.fromArray(e.v0), this.v1.fromArray(e.v1), this.v2.fromArray(e.v2), this;
  }
}
class Zd extends sn {
  constructor(e = new j(), t = new j(), r = new j()) {
    super(), this.isQuadraticBezierCurve3 = !0, this.type = "QuadraticBezierCurve3", this.v0 = e, this.v1 = t, this.v2 = r;
  }
  getPoint(e, t = new j()) {
    const r = t, n = this.v0, i = this.v1, s = this.v2;
    return r.set(
      Bi(e, n.x, i.x, s.x),
      Bi(e, n.y, i.y, s.y),
      Bi(e, n.z, i.z, s.z)
    ), r;
  }
  copy(e) {
    return super.copy(e), this.v0.copy(e.v0), this.v1.copy(e.v1), this.v2.copy(e.v2), this;
  }
  toJSON() {
    const e = super.toJSON();
    return e.v0 = this.v0.toArray(), e.v1 = this.v1.toArray(), e.v2 = this.v2.toArray(), e;
  }
  fromJSON(e) {
    return super.fromJSON(e), this.v0.fromArray(e.v0), this.v1.fromArray(e.v1), this.v2.fromArray(e.v2), this;
  }
}
class sl extends sn {
  constructor(e = []) {
    super(), this.isSplineCurve = !0, this.type = "SplineCurve", this.points = e;
  }
  getPoint(e, t = new Ce()) {
    const r = t, n = this.points, i = (n.length - 1) * e, s = Math.floor(i), o = i - s, l = n[s === 0 ? s : s - 1], c = n[s], u = n[s > n.length - 2 ? n.length - 1 : s + 1], f = n[s > n.length - 3 ? n.length - 1 : s + 2];
    return r.set(
      mo(o, l.x, c.x, u.x, f.x),
      mo(o, l.y, c.y, u.y, f.y)
    ), r;
  }
  copy(e) {
    super.copy(e), this.points = [];
    for (let t = 0, r = e.points.length; t < r; t++) {
      const n = e.points[t];
      this.points.push(n.clone());
    }
    return this;
  }
  toJSON() {
    const e = super.toJSON();
    e.points = [];
    for (let t = 0, r = this.points.length; t < r; t++) {
      const n = this.points[t];
      e.points.push(n.toArray());
    }
    return e;
  }
  fromJSON(e) {
    super.fromJSON(e), this.points = [];
    for (let t = 0, r = e.points.length; t < r; t++) {
      const n = e.points[t];
      this.points.push(new Ce().fromArray(n));
    }
    return this;
  }
}
var Va = /* @__PURE__ */ Object.freeze({
  __proto__: null,
  ArcCurve: nl,
  CatmullRomCurve3: kd,
  CubicBezierCurve: il,
  CubicBezierCurve3: Yd,
  EllipseCurve: zr,
  LineCurve: rl,
  LineCurve3: jd,
  QuadraticBezierCurve: al,
  QuadraticBezierCurve3: Zd,
  SplineCurve: sl
});
class Kd extends sn {
  constructor() {
    super(), this.type = "CurvePath", this.curves = [], this.autoClose = !1;
  }
  add(e) {
    this.curves.push(e);
  }
  closePath() {
    const e = this.curves[0].getPoint(0), t = this.curves[this.curves.length - 1].getPoint(1);
    if (!e.equals(t)) {
      const r = e.isVector2 === !0 ? "LineCurve" : "LineCurve3";
      this.curves.push(new Va[r](t, e));
    }
    return this;
  }
  // To get accurate point with reference to
  // entire path distance at time t,
  // following has to be done:
  // 1. Length of each sub path have to be known
  // 2. Locate and identify type of curve
  // 3. Get t for the curve
  // 4. Return curve.getPointAt(t')
  getPoint(e, t) {
    const r = e * this.getLength(), n = this.getCurveLengths();
    let i = 0;
    for (; i < n.length; ) {
      if (n[i] >= r) {
        const s = n[i] - r, o = this.curves[i], l = o.getLength(), c = l === 0 ? 0 : 1 - s / l;
        return o.getPointAt(c, t);
      }
      i++;
    }
    return null;
  }
  // We cannot use the default THREE.Curve getPoint() with getLength() because in
  // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  // getPoint() depends on getLength
  getLength() {
    const e = this.getCurveLengths();
    return e[e.length - 1];
  }
  // cacheLengths must be recalculated.
  updateArcLengths() {
    this.needsUpdate = !0, this.cacheLengths = null, this.getCurveLengths();
  }
  // Compute lengths and cache them
  // We cannot overwrite getLengths() because UtoT mapping uses it.
  getCurveLengths() {
    if (this.cacheLengths && this.cacheLengths.length === this.curves.length)
      return this.cacheLengths;
    const e = [];
    let t = 0;
    for (let r = 0, n = this.curves.length; r < n; r++)
      t += this.curves[r].getLength(), e.push(t);
    return this.cacheLengths = e, e;
  }
  getSpacedPoints(e = 40) {
    const t = [];
    for (let r = 0; r <= e; r++)
      t.push(this.getPoint(r / e));
    return this.autoClose && t.push(t[0]), t;
  }
  getPoints(e = 12) {
    const t = [];
    let r;
    for (let n = 0, i = this.curves; n < i.length; n++) {
      const s = i[n], o = s.isEllipseCurve ? e * 2 : s.isLineCurve || s.isLineCurve3 ? 1 : s.isSplineCurve ? e * s.points.length : e, l = s.getPoints(o);
      for (let c = 0; c < l.length; c++) {
        const u = l[c];
        r && r.equals(u) || (t.push(u), r = u);
      }
    }
    return this.autoClose && t.length > 1 && !t[t.length - 1].equals(t[0]) && t.push(t[0]), t;
  }
  copy(e) {
    super.copy(e), this.curves = [];
    for (let t = 0, r = e.curves.length; t < r; t++) {
      const n = e.curves[t];
      this.curves.push(n.clone());
    }
    return this.autoClose = e.autoClose, this;
  }
  toJSON() {
    const e = super.toJSON();
    e.autoClose = this.autoClose, e.curves = [];
    for (let t = 0, r = this.curves.length; t < r; t++) {
      const n = this.curves[t];
      e.curves.push(n.toJSON());
    }
    return e;
  }
  fromJSON(e) {
    super.fromJSON(e), this.autoClose = e.autoClose, this.curves = [];
    for (let t = 0, r = e.curves.length; t < r; t++) {
      const n = e.curves[t];
      this.curves.push(new Va[n.type]().fromJSON(n));
    }
    return this;
  }
}
class Ha extends Kd {
  constructor(e) {
    super(), this.type = "Path", this.currentPoint = new Ce(), e && this.setFromPoints(e);
  }
  setFromPoints(e) {
    this.moveTo(e[0].x, e[0].y);
    for (let t = 1, r = e.length; t < r; t++)
      this.lineTo(e[t].x, e[t].y);
    return this;
  }
  moveTo(e, t) {
    return this.currentPoint.set(e, t), this;
  }
  lineTo(e, t) {
    const r = new rl(this.currentPoint.clone(), new Ce(e, t));
    return this.curves.push(r), this.currentPoint.set(e, t), this;
  }
  quadraticCurveTo(e, t, r, n) {
    const i = new al(
      this.currentPoint.clone(),
      new Ce(e, t),
      new Ce(r, n)
    );
    return this.curves.push(i), this.currentPoint.set(r, n), this;
  }
  bezierCurveTo(e, t, r, n, i, s) {
    const o = new il(
      this.currentPoint.clone(),
      new Ce(e, t),
      new Ce(r, n),
      new Ce(i, s)
    );
    return this.curves.push(o), this.currentPoint.set(i, s), this;
  }
  splineThru(e) {
    const t = [this.currentPoint.clone()].concat(e), r = new sl(t);
    return this.curves.push(r), this.currentPoint.copy(e[e.length - 1]), this;
  }
  arc(e, t, r, n, i, s) {
    const o = this.currentPoint.x, l = this.currentPoint.y;
    return this.absarc(
      e + o,
      t + l,
      r,
      n,
      i,
      s
    ), this;
  }
  absarc(e, t, r, n, i, s) {
    return this.absellipse(e, t, r, r, n, i, s), this;
  }
  ellipse(e, t, r, n, i, s, o, l) {
    const c = this.currentPoint.x, u = this.currentPoint.y;
    return this.absellipse(e + c, t + u, r, n, i, s, o, l), this;
  }
  absellipse(e, t, r, n, i, s, o, l) {
    const c = new zr(e, t, r, n, i, s, o, l);
    if (this.curves.length > 0) {
      const f = c.getPoint(0);
      f.equals(this.currentPoint) || this.lineTo(f.x, f.y);
    }
    this.curves.push(c);
    const u = c.getPoint(1);
    return this.currentPoint.copy(u), this;
  }
  copy(e) {
    return super.copy(e), this.currentPoint.copy(e.currentPoint), this;
  }
  toJSON() {
    const e = super.toJSON();
    return e.currentPoint = this.currentPoint.toArray(), e;
  }
  fromJSON(e) {
    return super.fromJSON(e), this.currentPoint.fromArray(e.currentPoint), this;
  }
}
class Lr extends Ha {
  constructor(e) {
    super(e), this.uuid = mi(), this.type = "Shape", this.holes = [];
  }
  getPointsHoles(e) {
    const t = [];
    for (let r = 0, n = this.holes.length; r < n; r++)
      t[r] = this.holes[r].getPoints(e);
    return t;
  }
  // get points of shape and holes (keypoints based on segments parameter)
  extractPoints(e) {
    return {
      shape: this.getPoints(e),
      holes: this.getPointsHoles(e)
    };
  }
  copy(e) {
    super.copy(e), this.holes = [];
    for (let t = 0, r = e.holes.length; t < r; t++) {
      const n = e.holes[t];
      this.holes.push(n.clone());
    }
    return this;
  }
  toJSON() {
    const e = super.toJSON();
    e.uuid = this.uuid, e.holes = [];
    for (let t = 0, r = this.holes.length; t < r; t++) {
      const n = this.holes[t];
      e.holes.push(n.toJSON());
    }
    return e;
  }
  fromJSON(e) {
    super.fromJSON(e), this.uuid = e.uuid, this.holes = [];
    for (let t = 0, r = e.holes.length; t < r; t++) {
      const n = e.holes[t];
      this.holes.push(new Ha().fromJSON(n));
    }
    return this;
  }
}
const Jd = {
  triangulate: function(a, e, t = 2) {
    const r = e && e.length, n = r ? e[0] * t : a.length;
    let i = ol(a, 0, n, t, !0);
    const s = [];
    if (!i || i.next === i.prev) return s;
    let o, l, c, u, f, h, d;
    if (r && (i = np(a, e, i, t)), a.length > 80 * t) {
      o = c = a[0], l = u = a[1];
      for (let g = t; g < n; g += t)
        f = a[g], h = a[g + 1], f < o && (o = f), h < l && (l = h), f > c && (c = f), h > u && (u = h);
      d = Math.max(c - o, u - l), d = d !== 0 ? 32767 / d : 0;
    }
    return Hi(i, s, t, o, l, d, 0), s;
  }
};
function ol(a, e, t, r, n) {
  let i, s;
  if (n === dp(a, e, t, r) > 0)
    for (i = e; i < t; i += r) s = go(i, a[i], a[i + 1], s);
  else
    for (i = t - r; i >= e; i -= r) s = go(i, a[i], a[i + 1], s);
  return s && Vr(s, s.next) && (Xi(s), s = s.next), s;
}
function kn(a, e) {
  if (!a) return a;
  e || (e = a);
  let t = a, r;
  do
    if (r = !1, !t.steiner && (Vr(t, t.next) || lt(t.prev, t, t.next) === 0)) {
      if (Xi(t), t = e = t.prev, t === t.next) break;
      r = !0;
    } else
      t = t.next;
  while (r || t !== e);
  return e;
}
function Hi(a, e, t, r, n, i, s) {
  if (!a) return;
  !s && i && op(a, r, n, i);
  let o = a, l, c;
  for (; a.prev !== a.next; ) {
    if (l = a.prev, c = a.next, i ? $d(a, r, n, i) : Qd(a)) {
      e.push(l.i / t | 0), e.push(a.i / t | 0), e.push(c.i / t | 0), Xi(a), a = c.next, o = c.next;
      continue;
    }
    if (a = c, a === o) {
      s ? s === 1 ? (a = ep(kn(a), e, t), Hi(a, e, t, r, n, i, 2)) : s === 2 && tp(a, e, t, r, n, i) : Hi(kn(a), e, t, r, n, i, 1);
      break;
    }
  }
}
function Qd(a) {
  const e = a.prev, t = a, r = a.next;
  if (lt(e, t, r) >= 0) return !1;
  const n = e.x, i = t.x, s = r.x, o = e.y, l = t.y, c = r.y, u = n < i ? n < s ? n : s : i < s ? i : s, f = o < l ? o < c ? o : c : l < c ? l : c, h = n > i ? n > s ? n : s : i > s ? i : s, d = o > l ? o > c ? o : c : l > c ? l : c;
  let g = r.next;
  for (; g !== e; ) {
    if (g.x >= u && g.x <= h && g.y >= f && g.y <= d && ci(n, o, i, l, s, c, g.x, g.y) && lt(g.prev, g, g.next) >= 0) return !1;
    g = g.next;
  }
  return !0;
}
function $d(a, e, t, r) {
  const n = a.prev, i = a, s = a.next;
  if (lt(n, i, s) >= 0) return !1;
  const o = n.x, l = i.x, c = s.x, u = n.y, f = i.y, h = s.y, d = o < l ? o < c ? o : c : l < c ? l : c, g = u < f ? u < h ? u : h : f < h ? f : h, v = o > l ? o > c ? o : c : l > c ? l : c, m = u > f ? u > h ? u : h : f > h ? f : h, p = Wa(d, g, e, t, r), T = Wa(v, m, e, t, r);
  let x = a.prevZ, _ = a.nextZ;
  for (; x && x.z >= p && _ && _.z <= T; ) {
    if (x.x >= d && x.x <= v && x.y >= g && x.y <= m && x !== n && x !== s && ci(o, u, l, f, c, h, x.x, x.y) && lt(x.prev, x, x.next) >= 0 || (x = x.prevZ, _.x >= d && _.x <= v && _.y >= g && _.y <= m && _ !== n && _ !== s && ci(o, u, l, f, c, h, _.x, _.y) && lt(_.prev, _, _.next) >= 0)) return !1;
    _ = _.nextZ;
  }
  for (; x && x.z >= p; ) {
    if (x.x >= d && x.x <= v && x.y >= g && x.y <= m && x !== n && x !== s && ci(o, u, l, f, c, h, x.x, x.y) && lt(x.prev, x, x.next) >= 0) return !1;
    x = x.prevZ;
  }
  for (; _ && _.z <= T; ) {
    if (_.x >= d && _.x <= v && _.y >= g && _.y <= m && _ !== n && _ !== s && ci(o, u, l, f, c, h, _.x, _.y) && lt(_.prev, _, _.next) >= 0) return !1;
    _ = _.nextZ;
  }
  return !0;
}
function ep(a, e, t) {
  let r = a;
  do {
    const n = r.prev, i = r.next.next;
    !Vr(n, i) && ll(n, r, r.next, i) && Wi(n, i) && Wi(i, n) && (e.push(n.i / t | 0), e.push(r.i / t | 0), e.push(i.i / t | 0), Xi(r), Xi(r.next), r = a = i), r = r.next;
  } while (r !== a);
  return kn(r);
}
function tp(a, e, t, r, n, i) {
  let s = a;
  do {
    let o = s.next.next;
    for (; o !== s.prev; ) {
      if (s.i !== o.i && up(s, o)) {
        let l = cl(s, o);
        s = kn(s, s.next), l = kn(l, l.next), Hi(s, e, t, r, n, i, 0), Hi(l, e, t, r, n, i, 0);
        return;
      }
      o = o.next;
    }
    s = s.next;
  } while (s !== a);
}
function np(a, e, t, r) {
  const n = [];
  let i, s, o, l, c;
  for (i = 0, s = e.length; i < s; i++)
    o = e[i] * r, l = i < s - 1 ? e[i + 1] * r : a.length, c = ol(a, o, l, r, !1), c === c.next && (c.steiner = !0), n.push(cp(c));
  for (n.sort(ip), i = 0; i < n.length; i++)
    t = rp(n[i], t);
  return t;
}
function ip(a, e) {
  return a.x - e.x;
}
function rp(a, e) {
  const t = ap(a, e);
  if (!t)
    return e;
  const r = cl(t, a);
  return kn(r, r.next), kn(t, t.next);
}
function ap(a, e) {
  let t = e, r = -1 / 0, n;
  const i = a.x, s = a.y;
  do {
    if (s <= t.y && s >= t.next.y && t.next.y !== t.y) {
      const h = t.x + (s - t.y) * (t.next.x - t.x) / (t.next.y - t.y);
      if (h <= i && h > r && (r = h, n = t.x < t.next.x ? t : t.next, h === i))
        return n;
    }
    t = t.next;
  } while (t !== e);
  if (!n) return null;
  const o = n, l = n.x, c = n.y;
  let u = 1 / 0, f;
  t = n;
  do
    i >= t.x && t.x >= l && i !== t.x && ci(s < c ? i : r, s, l, c, s < c ? r : i, s, t.x, t.y) && (f = Math.abs(s - t.y) / (i - t.x), Wi(t, a) && (f < u || f === u && (t.x > n.x || t.x === n.x && sp(n, t))) && (n = t, u = f)), t = t.next;
  while (t !== o);
  return n;
}
function sp(a, e) {
  return lt(a.prev, a, e.prev) < 0 && lt(e.next, a, a.next) < 0;
}
function op(a, e, t, r) {
  let n = a;
  do
    n.z === 0 && (n.z = Wa(n.x, n.y, e, t, r)), n.prevZ = n.prev, n.nextZ = n.next, n = n.next;
  while (n !== a);
  n.prevZ.nextZ = null, n.prevZ = null, lp(n);
}
function lp(a) {
  let e, t, r, n, i, s, o, l, c = 1;
  do {
    for (t = a, a = null, i = null, s = 0; t; ) {
      for (s++, r = t, o = 0, e = 0; e < c && (o++, r = r.nextZ, !!r); e++)
        ;
      for (l = c; o > 0 || l > 0 && r; )
        o !== 0 && (l === 0 || !r || t.z <= r.z) ? (n = t, t = t.nextZ, o--) : (n = r, r = r.nextZ, l--), i ? i.nextZ = n : a = n, n.prevZ = i, i = n;
      t = r;
    }
    i.nextZ = null, c *= 2;
  } while (s > 1);
  return a;
}
function Wa(a, e, t, r, n) {
  return a = (a - t) * n | 0, e = (e - r) * n | 0, a = (a | a << 8) & 16711935, a = (a | a << 4) & 252645135, a = (a | a << 2) & 858993459, a = (a | a << 1) & 1431655765, e = (e | e << 8) & 16711935, e = (e | e << 4) & 252645135, e = (e | e << 2) & 858993459, e = (e | e << 1) & 1431655765, a | e << 1;
}
function cp(a) {
  let e = a, t = a;
  do
    (e.x < t.x || e.x === t.x && e.y < t.y) && (t = e), e = e.next;
  while (e !== a);
  return t;
}
function ci(a, e, t, r, n, i, s, o) {
  return (n - s) * (e - o) >= (a - s) * (i - o) && (a - s) * (r - o) >= (t - s) * (e - o) && (t - s) * (i - o) >= (n - s) * (r - o);
}
function up(a, e) {
  return a.next.i !== e.i && a.prev.i !== e.i && !hp(a, e) && // dones't intersect other edges
  (Wi(a, e) && Wi(e, a) && fp(a, e) && // locally visible
  (lt(a.prev, a, e.prev) || lt(a, e.prev, e)) || // does not create opposite-facing sectors
  Vr(a, e) && lt(a.prev, a, a.next) > 0 && lt(e.prev, e, e.next) > 0);
}
function lt(a, e, t) {
  return (e.y - a.y) * (t.x - e.x) - (e.x - a.x) * (t.y - e.y);
}
function Vr(a, e) {
  return a.x === e.x && a.y === e.y;
}
function ll(a, e, t, r) {
  const n = Rr(lt(a, e, t)), i = Rr(lt(a, e, r)), s = Rr(lt(t, r, a)), o = Rr(lt(t, r, e));
  return !!(n !== i && s !== o || n === 0 && Cr(a, t, e) || i === 0 && Cr(a, r, e) || s === 0 && Cr(t, a, r) || o === 0 && Cr(t, e, r));
}
function Cr(a, e, t) {
  return e.x <= Math.max(a.x, t.x) && e.x >= Math.min(a.x, t.x) && e.y <= Math.max(a.y, t.y) && e.y >= Math.min(a.y, t.y);
}
function Rr(a) {
  return a > 0 ? 1 : a < 0 ? -1 : 0;
}
function hp(a, e) {
  let t = a;
  do {
    if (t.i !== a.i && t.next.i !== a.i && t.i !== e.i && t.next.i !== e.i && ll(t, t.next, a, e)) return !0;
    t = t.next;
  } while (t !== a);
  return !1;
}
function Wi(a, e) {
  return lt(a.prev, a, a.next) < 0 ? lt(a, e, a.next) >= 0 && lt(a, a.prev, e) >= 0 : lt(a, e, a.prev) < 0 || lt(a, a.next, e) < 0;
}
function fp(a, e) {
  let t = a, r = !1;
  const n = (a.x + e.x) / 2, i = (a.y + e.y) / 2;
  do
    t.y > i != t.next.y > i && t.next.y !== t.y && n < (t.next.x - t.x) * (i - t.y) / (t.next.y - t.y) + t.x && (r = !r), t = t.next;
  while (t !== a);
  return r;
}
function cl(a, e) {
  const t = new Xa(a.i, a.x, a.y), r = new Xa(e.i, e.x, e.y), n = a.next, i = e.prev;
  return a.next = e, e.prev = a, t.next = n, n.prev = t, r.next = t, t.prev = r, i.next = r, r.prev = i, r;
}
function go(a, e, t, r) {
  const n = new Xa(a, e, t);
  return r ? (n.next = r.next, n.prev = r, r.next.prev = n, r.next = n) : (n.prev = n, n.next = n), n;
}
function Xi(a) {
  a.next.prev = a.prev, a.prev.next = a.next, a.prevZ && (a.prevZ.nextZ = a.nextZ), a.nextZ && (a.nextZ.prevZ = a.prevZ);
}
function Xa(a, e, t) {
  this.i = a, this.x = e, this.y = t, this.prev = null, this.next = null, this.z = 0, this.prevZ = null, this.nextZ = null, this.steiner = !1;
}
function dp(a, e, t, r) {
  let n = 0;
  for (let i = e, s = t - r; i < t; i += r)
    n += (a[s] - a[i]) * (a[i + 1] + a[s + 1]), s = i;
  return n;
}
class fi {
  // calculate area of the contour polygon
  static area(e) {
    const t = e.length;
    let r = 0;
    for (let n = t - 1, i = 0; i < t; n = i++)
      r += e[n].x * e[i].y - e[i].x * e[n].y;
    return r * 0.5;
  }
  static isClockWise(e) {
    return fi.area(e) < 0;
  }
  static triangulateShape(e, t) {
    const r = [], n = [], i = [];
    vo(e), _o(r, e);
    let s = e.length;
    t.forEach(vo);
    for (let l = 0; l < t.length; l++)
      n.push(s), s += t[l].length, _o(r, t[l]);
    const o = Jd.triangulate(r, n);
    for (let l = 0; l < o.length; l += 3)
      i.push(o.slice(l, l + 3));
    return i;
  }
}
function vo(a) {
  const e = a.length;
  e > 2 && a[e - 1].equals(a[0]) && a.pop();
}
function _o(a, e) {
  for (let t = 0; t < e.length; t++)
    a.push(e[t].x), a.push(e[t].y);
}
class ts extends St {
  constructor(e = new Lr([new Ce(0.5, 0.5), new Ce(-0.5, 0.5), new Ce(-0.5, -0.5), new Ce(0.5, -0.5)]), t = {}) {
    super(), this.type = "ExtrudeGeometry", this.parameters = {
      shapes: e,
      options: t
    }, e = Array.isArray(e) ? e : [e];
    const r = this, n = [], i = [];
    for (let o = 0, l = e.length; o < l; o++) {
      const c = e[o];
      s(c);
    }
    this.setAttribute("position", new tn(n, 3)), this.setAttribute("uv", new tn(i, 2)), this.computeVertexNormals();
    function s(o) {
      const l = [], c = t.curveSegments !== void 0 ? t.curveSegments : 12, u = t.steps !== void 0 ? t.steps : 1, f = t.depth !== void 0 ? t.depth : 1;
      let h = t.bevelEnabled !== void 0 ? t.bevelEnabled : !0, d = t.bevelThickness !== void 0 ? t.bevelThickness : 0.2, g = t.bevelSize !== void 0 ? t.bevelSize : d - 0.1, v = t.bevelOffset !== void 0 ? t.bevelOffset : 0, m = t.bevelSegments !== void 0 ? t.bevelSegments : 3;
      const p = t.extrudePath, T = t.UVGenerator !== void 0 ? t.UVGenerator : pp;
      let x, _ = !1, D, C, A, R;
      p && (x = p.getSpacedPoints(u), _ = !0, h = !1, D = p.computeFrenetFrames(u, !1), C = new j(), A = new j(), R = new j()), h || (m = 0, d = 0, g = 0, v = 0);
      const E = o.extractPoints(c);
      let S = E.shape;
      const F = E.holes;
      if (!fi.isClockWise(S)) {
        S = S.reverse();
        for (let W = 0, ce = F.length; W < ce; W++) {
          const P = F[W];
          fi.isClockWise(P) && (F[W] = P.reverse());
        }
      }
      const B = fi.triangulateShape(S, F), k = S;
      for (let W = 0, ce = F.length; W < ce; W++) {
        const P = F[W];
        S = S.concat(P);
      }
      function O(W, ce, P) {
        return ce || console.error("THREE.ExtrudeGeometry: vec does not exist"), W.clone().addScaledVector(ce, P);
      }
      const z = S.length, ne = B.length;
      function q(W, ce, P) {
        let pe, ae, ve;
        const te = W.x - ce.x, Te = W.y - ce.y, me = P.x - W.x, M = P.y - W.y, y = te * te + Te * Te, H = te * M - Te * me;
        if (Math.abs(H) > Number.EPSILON) {
          const $ = Math.sqrt(y), ee = Math.sqrt(me * me + M * M), oe = ce.x - Te / $, Se = ce.y + te / $, de = P.x - M / ee, xe = P.y + me / ee, De = ((de - oe) * M - (xe - Se) * me) / (te * M - Te * me);
          pe = oe + te * De - W.x, ae = Se + Te * De - W.y;
          const ye = pe * pe + ae * ae;
          if (ye <= 2)
            return new Ce(pe, ae);
          ve = Math.sqrt(ye / 2);
        } else {
          let $ = !1;
          te > Number.EPSILON ? me > Number.EPSILON && ($ = !0) : te < -Number.EPSILON ? me < -Number.EPSILON && ($ = !0) : Math.sign(Te) === Math.sign(M) && ($ = !0), $ ? (pe = -Te, ae = te, ve = Math.sqrt(y)) : (pe = te, ae = Te, ve = Math.sqrt(y / 2));
        }
        return new Ce(pe / ve, ae / ve);
      }
      const K = [];
      for (let W = 0, ce = k.length, P = ce - 1, pe = W + 1; W < ce; W++, P++, pe++)
        P === ce && (P = 0), pe === ce && (pe = 0), K[W] = q(k[W], k[P], k[pe]);
      const Z = [];
      let N, Y = K.concat();
      for (let W = 0, ce = F.length; W < ce; W++) {
        const P = F[W];
        N = [];
        for (let pe = 0, ae = P.length, ve = ae - 1, te = pe + 1; pe < ae; pe++, ve++, te++)
          ve === ae && (ve = 0), te === ae && (te = 0), N[pe] = q(P[pe], P[ve], P[te]);
        Z.push(N), Y = Y.concat(N);
      }
      for (let W = 0; W < m; W++) {
        const ce = W / m, P = d * Math.cos(ce * Math.PI / 2), pe = g * Math.sin(ce * Math.PI / 2) + v;
        for (let ae = 0, ve = k.length; ae < ve; ae++) {
          const te = O(k[ae], K[ae], pe);
          I(te.x, te.y, -P);
        }
        for (let ae = 0, ve = F.length; ae < ve; ae++) {
          const te = F[ae];
          N = Z[ae];
          for (let Te = 0, me = te.length; Te < me; Te++) {
            const M = O(te[Te], N[Te], pe);
            I(M.x, M.y, -P);
          }
        }
      }
      const ie = g + v;
      for (let W = 0; W < z; W++) {
        const ce = h ? O(S[W], Y[W], ie) : S[W];
        _ ? (A.copy(D.normals[0]).multiplyScalar(ce.x), C.copy(D.binormals[0]).multiplyScalar(ce.y), R.copy(x[0]).add(A).add(C), I(R.x, R.y, R.z)) : I(ce.x, ce.y, 0);
      }
      for (let W = 1; W <= u; W++)
        for (let ce = 0; ce < z; ce++) {
          const P = h ? O(S[ce], Y[ce], ie) : S[ce];
          _ ? (A.copy(D.normals[W]).multiplyScalar(P.x), C.copy(D.binormals[W]).multiplyScalar(P.y), R.copy(x[W]).add(A).add(C), I(R.x, R.y, R.z)) : I(P.x, P.y, f / u * W);
        }
      for (let W = m - 1; W >= 0; W--) {
        const ce = W / m, P = d * Math.cos(ce * Math.PI / 2), pe = g * Math.sin(ce * Math.PI / 2) + v;
        for (let ae = 0, ve = k.length; ae < ve; ae++) {
          const te = O(k[ae], K[ae], pe);
          I(te.x, te.y, f + P);
        }
        for (let ae = 0, ve = F.length; ae < ve; ae++) {
          const te = F[ae];
          N = Z[ae];
          for (let Te = 0, me = te.length; Te < me; Te++) {
            const M = O(te[Te], N[Te], pe);
            _ ? I(M.x, M.y + x[u - 1].y, x[u - 1].x + P) : I(M.x, M.y, f + P);
          }
        }
      }
      b(), U();
      function b() {
        const W = n.length / 3;
        if (h) {
          let ce = 0, P = z * ce;
          for (let pe = 0; pe < ne; pe++) {
            const ae = B[pe];
            V(ae[2] + P, ae[1] + P, ae[0] + P);
          }
          ce = u + m * 2, P = z * ce;
          for (let pe = 0; pe < ne; pe++) {
            const ae = B[pe];
            V(ae[0] + P, ae[1] + P, ae[2] + P);
          }
        } else {
          for (let ce = 0; ce < ne; ce++) {
            const P = B[ce];
            V(P[2], P[1], P[0]);
          }
          for (let ce = 0; ce < ne; ce++) {
            const P = B[ce];
            V(P[0] + z * u, P[1] + z * u, P[2] + z * u);
          }
        }
        r.addGroup(W, n.length / 3 - W, 0);
      }
      function U() {
        const W = n.length / 3;
        let ce = 0;
        G(k, ce), ce += k.length;
        for (let P = 0, pe = F.length; P < pe; P++) {
          const ae = F[P];
          G(ae, ce), ce += ae.length;
        }
        r.addGroup(W, n.length / 3 - W, 1);
      }
      function G(W, ce) {
        let P = W.length;
        for (; --P >= 0; ) {
          const pe = P;
          let ae = P - 1;
          ae < 0 && (ae = W.length - 1);
          for (let ve = 0, te = u + m * 2; ve < te; ve++) {
            const Te = z * ve, me = z * (ve + 1), M = ce + pe + Te, y = ce + ae + Te, H = ce + ae + me, $ = ce + pe + me;
            re(M, y, H, $);
          }
        }
      }
      function I(W, ce, P) {
        l.push(W), l.push(ce), l.push(P);
      }
      function V(W, ce, P) {
        he(W), he(ce), he(P);
        const pe = n.length / 3, ae = T.generateTopUV(r, n, pe - 3, pe - 2, pe - 1);
        fe(ae[0]), fe(ae[1]), fe(ae[2]);
      }
      function re(W, ce, P, pe) {
        he(W), he(ce), he(pe), he(ce), he(P), he(pe);
        const ae = n.length / 3, ve = T.generateSideWallUV(r, n, ae - 6, ae - 3, ae - 2, ae - 1);
        fe(ve[0]), fe(ve[1]), fe(ve[3]), fe(ve[1]), fe(ve[2]), fe(ve[3]);
      }
      function he(W) {
        n.push(l[W * 3 + 0]), n.push(l[W * 3 + 1]), n.push(l[W * 3 + 2]);
      }
      function fe(W) {
        i.push(W.x), i.push(W.y);
      }
    }
  }
  copy(e) {
    return super.copy(e), this.parameters = Object.assign({}, e.parameters), this;
  }
  toJSON() {
    const e = super.toJSON(), t = this.parameters.shapes, r = this.parameters.options;
    return mp(t, r, e);
  }
  static fromJSON(e, t) {
    const r = [];
    for (let i = 0, s = e.shapes.length; i < s; i++) {
      const o = t[e.shapes[i]];
      r.push(o);
    }
    const n = e.options.extrudePath;
    return n !== void 0 && (e.options.extrudePath = new Va[n.type]().fromJSON(n)), new ts(r, e.options);
  }
}
const pp = {
  generateTopUV: function(a, e, t, r, n) {
    const i = e[t * 3], s = e[t * 3 + 1], o = e[r * 3], l = e[r * 3 + 1], c = e[n * 3], u = e[n * 3 + 1];
    return [
      new Ce(i, s),
      new Ce(o, l),
      new Ce(c, u)
    ];
  },
  generateSideWallUV: function(a, e, t, r, n, i) {
    const s = e[t * 3], o = e[t * 3 + 1], l = e[t * 3 + 2], c = e[r * 3], u = e[r * 3 + 1], f = e[r * 3 + 2], h = e[n * 3], d = e[n * 3 + 1], g = e[n * 3 + 2], v = e[i * 3], m = e[i * 3 + 1], p = e[i * 3 + 2];
    return Math.abs(o - u) < Math.abs(s - c) ? [
      new Ce(s, 1 - l),
      new Ce(c, 1 - f),
      new Ce(h, 1 - g),
      new Ce(v, 1 - p)
    ] : [
      new Ce(o, 1 - l),
      new Ce(u, 1 - f),
      new Ce(d, 1 - g),
      new Ce(m, 1 - p)
    ];
  }
};
function mp(a, e, t) {
  if (t.shapes = [], Array.isArray(a))
    for (let r = 0, n = a.length; r < n; r++) {
      const i = a[r];
      t.shapes.push(i.uuid);
    }
  else
    t.shapes.push(a.uuid);
  return t.options = Object.assign({}, e), e.extrudePath !== void 0 && (t.options.extrudePath = e.extrudePath.toJSON()), t;
}
class gp extends li {
  static get type() {
    return "LineDashedMaterial";
  }
  constructor(e) {
    super(), this.isLineDashedMaterial = !0, this.scale = 1, this.dashSize = 3, this.gapSize = 1, this.setValues(e);
  }
  copy(e) {
    return super.copy(e), this.scale = e.scale, this.dashSize = e.dashSize, this.gapSize = e.gapSize, this;
  }
}
const xo = {
  enabled: !1,
  files: {},
  add: function(a, e) {
    this.enabled !== !1 && (this.files[a] = e);
  },
  get: function(a) {
    if (this.enabled !== !1)
      return this.files[a];
  },
  remove: function(a) {
    delete this.files[a];
  },
  clear: function() {
    this.files = {};
  }
};
class vp {
  constructor(e, t, r) {
    const n = this;
    let i = !1, s = 0, o = 0, l;
    const c = [];
    this.onStart = void 0, this.onLoad = e, this.onProgress = t, this.onError = r, this.itemStart = function(u) {
      o++, i === !1 && n.onStart !== void 0 && n.onStart(u, s, o), i = !0;
    }, this.itemEnd = function(u) {
      s++, n.onProgress !== void 0 && n.onProgress(u, s, o), s === o && (i = !1, n.onLoad !== void 0 && n.onLoad());
    }, this.itemError = function(u) {
      n.onError !== void 0 && n.onError(u);
    }, this.resolveURL = function(u) {
      return l ? l(u) : u;
    }, this.setURLModifier = function(u) {
      return l = u, this;
    }, this.addHandler = function(u, f) {
      return c.push(u, f), this;
    }, this.removeHandler = function(u) {
      const f = c.indexOf(u);
      return f !== -1 && c.splice(f, 2), this;
    }, this.getHandler = function(u) {
      for (let f = 0, h = c.length; f < h; f += 2) {
        const d = c[f], g = c[f + 1];
        if (d.global && (d.lastIndex = 0), d.test(u))
          return g;
      }
      return null;
    };
  }
}
const _p = /* @__PURE__ */ new vp();
class ns {
  constructor(e) {
    this.manager = e !== void 0 ? e : _p, this.crossOrigin = "anonymous", this.withCredentials = !1, this.path = "", this.resourcePath = "", this.requestHeader = {};
  }
  load() {
  }
  loadAsync(e, t) {
    const r = this;
    return new Promise(function(n, i) {
      r.load(e, n, t, i);
    });
  }
  parse() {
  }
  setCrossOrigin(e) {
    return this.crossOrigin = e, this;
  }
  setWithCredentials(e) {
    return this.withCredentials = e, this;
  }
  setPath(e) {
    return this.path = e, this;
  }
  setResourcePath(e) {
    return this.resourcePath = e, this;
  }
  setRequestHeader(e) {
    return this.requestHeader = e, this;
  }
}
ns.DEFAULT_MATERIAL_NAME = "__DEFAULT";
const dn = {};
class xp extends Error {
  constructor(e, t) {
    super(e), this.response = t;
  }
}
class Sp extends ns {
  constructor(e) {
    super(e);
  }
  load(e, t, r, n) {
    e === void 0 && (e = ""), this.path !== void 0 && (e = this.path + e), e = this.manager.resolveURL(e);
    const i = xo.get(e);
    if (i !== void 0)
      return this.manager.itemStart(e), setTimeout(() => {
        t && t(i), this.manager.itemEnd(e);
      }, 0), i;
    if (dn[e] !== void 0) {
      dn[e].push({
        onLoad: t,
        onProgress: r,
        onError: n
      });
      return;
    }
    dn[e] = [], dn[e].push({
      onLoad: t,
      onProgress: r,
      onError: n
    });
    const s = new Request(e, {
      headers: new Headers(this.requestHeader),
      credentials: this.withCredentials ? "include" : "same-origin"
      // An abort controller could be added within a future PR
    }), o = this.mimeType, l = this.responseType;
    fetch(s).then((c) => {
      if (c.status === 200 || c.status === 0) {
        if (c.status === 0 && console.warn("THREE.FileLoader: HTTP Status 0 received."), typeof ReadableStream > "u" || c.body === void 0 || c.body.getReader === void 0)
          return c;
        const u = dn[e], f = c.body.getReader(), h = c.headers.get("X-File-Size") || c.headers.get("Content-Length"), d = h ? parseInt(h) : 0, g = d !== 0;
        let v = 0;
        const m = new ReadableStream({
          start(p) {
            T();
            function T() {
              f.read().then(({ done: x, value: _ }) => {
                if (x)
                  p.close();
                else {
                  v += _.byteLength;
                  const D = new ProgressEvent("progress", { lengthComputable: g, loaded: v, total: d });
                  for (let C = 0, A = u.length; C < A; C++) {
                    const R = u[C];
                    R.onProgress && R.onProgress(D);
                  }
                  p.enqueue(_), T();
                }
              }, (x) => {
                p.error(x);
              });
            }
          }
        });
        return new Response(m);
      } else
        throw new xp(`fetch for "${c.url}" responded with ${c.status}: ${c.statusText}`, c);
    }).then((c) => {
      switch (l) {
        case "arraybuffer":
          return c.arrayBuffer();
        case "blob":
          return c.blob();
        case "document":
          return c.text().then((u) => new DOMParser().parseFromString(u, o));
        case "json":
          return c.json();
        default:
          if (o === void 0)
            return c.text();
          {
            const f = /charset="?([^;"\s]*)"?/i.exec(o), h = f && f[1] ? f[1].toLowerCase() : void 0, d = new TextDecoder(h);
            return c.arrayBuffer().then((g) => d.decode(g));
          }
      }
    }).then((c) => {
      xo.add(e, c);
      const u = dn[e];
      delete dn[e];
      for (let f = 0, h = u.length; f < h; f++) {
        const d = u[f];
        d.onLoad && d.onLoad(c);
      }
    }).catch((c) => {
      const u = dn[e];
      if (u === void 0)
        throw this.manager.itemError(e), c;
      delete dn[e];
      for (let f = 0, h = u.length; f < h; f++) {
        const d = u[f];
        d.onError && d.onError(c);
      }
      this.manager.itemError(e);
    }).finally(() => {
      this.manager.itemEnd(e);
    }), this.manager.itemStart(e);
  }
  setResponseType(e) {
    return this.responseType = e, this;
  }
  setMimeType(e) {
    return this.mimeType = e, this;
  }
}
class yp extends St {
  constructor() {
    super(), this.isInstancedBufferGeometry = !0, this.type = "InstancedBufferGeometry", this.instanceCount = 1 / 0;
  }
  copy(e) {
    return super.copy(e), this.instanceCount = e.instanceCount, this;
  }
  toJSON() {
    const e = super.toJSON();
    return e.instanceCount = this.instanceCount, e.isInstancedBufferGeometry = !0, e;
  }
}
class Mp {
  constructor() {
    this.type = "ShapePath", this.color = new Ke(), this.subPaths = [], this.currentPath = null;
  }
  moveTo(e, t) {
    return this.currentPath = new Ha(), this.subPaths.push(this.currentPath), this.currentPath.moveTo(e, t), this;
  }
  lineTo(e, t) {
    return this.currentPath.lineTo(e, t), this;
  }
  quadraticCurveTo(e, t, r, n) {
    return this.currentPath.quadraticCurveTo(e, t, r, n), this;
  }
  bezierCurveTo(e, t, r, n, i, s) {
    return this.currentPath.bezierCurveTo(e, t, r, n, i, s), this;
  }
  splineThru(e) {
    return this.currentPath.splineThru(e), this;
  }
  toShapes(e) {
    function t(p) {
      const T = [];
      for (let x = 0, _ = p.length; x < _; x++) {
        const D = p[x], C = new Lr();
        C.curves = D.curves, T.push(C);
      }
      return T;
    }
    function r(p, T) {
      const x = T.length;
      let _ = !1;
      for (let D = x - 1, C = 0; C < x; D = C++) {
        let A = T[D], R = T[C], E = R.x - A.x, S = R.y - A.y;
        if (Math.abs(S) > Number.EPSILON) {
          if (S < 0 && (A = T[C], E = -E, R = T[D], S = -S), p.y < A.y || p.y > R.y) continue;
          if (p.y === A.y) {
            if (p.x === A.x) return !0;
          } else {
            const F = S * (p.x - A.x) - E * (p.y - A.y);
            if (F === 0) return !0;
            if (F < 0) continue;
            _ = !_;
          }
        } else {
          if (p.y !== A.y) continue;
          if (R.x <= p.x && p.x <= A.x || A.x <= p.x && p.x <= R.x) return !0;
        }
      }
      return _;
    }
    const n = fi.isClockWise, i = this.subPaths;
    if (i.length === 0) return [];
    let s, o, l;
    const c = [];
    if (i.length === 1)
      return o = i[0], l = new Lr(), l.curves = o.curves, c.push(l), c;
    let u = !n(i[0].getPoints());
    u = e ? !u : u;
    const f = [], h = [];
    let d = [], g = 0, v;
    h[g] = void 0, d[g] = [];
    for (let p = 0, T = i.length; p < T; p++)
      o = i[p], v = o.getPoints(), s = n(v), s = e ? !s : s, s ? (!u && h[g] && g++, h[g] = { s: new Lr(), p: v }, h[g].s.curves = o.curves, u && g++, d[g] = []) : d[g].push({ h: o, p: v[0] });
    if (!h[0]) return t(i);
    if (h.length > 1) {
      let p = !1, T = 0;
      for (let x = 0, _ = h.length; x < _; x++)
        f[x] = [];
      for (let x = 0, _ = h.length; x < _; x++) {
        const D = d[x];
        for (let C = 0; C < D.length; C++) {
          const A = D[C];
          let R = !0;
          for (let E = 0; E < h.length; E++)
            r(A.p, h[E].p) && (x !== E && T++, R ? (R = !1, f[E].push(A)) : p = !0);
          R && f[x].push(A);
        }
      }
      T > 0 && p === !1 && (d = f);
    }
    let m;
    for (let p = 0, T = h.length; p < T; p++) {
      l = h[p].s, c.push(l), m = d[p];
      for (let x = 0, _ = m.length; x < _; x++)
        l.holes.push(m[x].h);
    }
    return c;
  }
}
typeof __THREE_DEVTOOLS__ < "u" && __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register", { detail: {
  revision: Ka
} }));
typeof window < "u" && (window.__THREE__ ? console.warn("WARNING: Multiple instances of Three.js being imported.") : window.__THREE__ = Ka);
class Ep extends ts {
  constructor(e, t = {}) {
    const r = t.font;
    if (r === void 0)
      super();
    else {
      const n = r.generateShapes(e, t.size);
      t.depth === void 0 && t.height !== void 0 && console.warn("THREE.TextGeometry: .height is now depreciated. Please use .depth instead"), t.depth = t.depth !== void 0 ? t.depth : t.height !== void 0 ? t.height : 50, t.bevelThickness === void 0 && (t.bevelThickness = 10), t.bevelSize === void 0 && (t.bevelSize = 8), t.bevelEnabled === void 0 && (t.bevelEnabled = !1), super(n, t);
    }
    this.type = "TextGeometry";
  }
}
class Tp extends ns {
  constructor(e) {
    super(e);
  }
  load(e, t, r, n) {
    const i = this, s = new Sp(this.manager);
    s.setPath(this.path), s.setRequestHeader(this.requestHeader), s.setWithCredentials(this.withCredentials), s.load(e, function(o) {
      const l = i.parse(JSON.parse(o));
      t && t(l);
    }, r, n);
  }
  parse(e) {
    return new bp(e);
  }
}
class bp {
  constructor(e) {
    this.isFont = !0, this.type = "Font", this.data = e;
  }
  generateShapes(e, t = 100) {
    const r = [], n = Ap(e, t, this.data);
    for (let i = 0, s = n.length; i < s; i++)
      r.push(...n[i].toShapes());
    return r;
  }
}
function Ap(a, e, t) {
  const r = Array.from(a), n = e / t.resolution, i = (t.boundingBox.yMax - t.boundingBox.yMin + t.underlineThickness) * n, s = [];
  let o = 0, l = 0;
  for (let c = 0; c < r.length; c++) {
    const u = r[c];
    if (u === `
`)
      o = 0, l -= i;
    else {
      const f = wp(u, n, o, l, t);
      o += f.offsetX, s.push(f.path);
    }
  }
  return s;
}
function wp(a, e, t, r, n) {
  const i = n.glyphs[a] || n.glyphs["?"];
  if (!i) {
    console.error('THREE.Font: character "' + a + '" does not exists in font family ' + n.familyName + ".");
    return;
  }
  const s = new Mp();
  let o, l, c, u, f, h, d, g;
  if (i.o) {
    const v = i._cachedOutline || (i._cachedOutline = i.o.split(" "));
    for (let m = 0, p = v.length; m < p; )
      switch (v[m++]) {
        case "m":
          o = v[m++] * e + t, l = v[m++] * e + r, s.moveTo(o, l);
          break;
        case "l":
          o = v[m++] * e + t, l = v[m++] * e + r, s.lineTo(o, l);
          break;
        case "q":
          c = v[m++] * e + t, u = v[m++] * e + r, f = v[m++] * e + t, h = v[m++] * e + r, s.quadraticCurveTo(f, h, c, u);
          break;
        case "b":
          c = v[m++] * e + t, u = v[m++] * e + r, f = v[m++] * e + t, h = v[m++] * e + r, d = v[m++] * e + t, g = v[m++] * e + r, s.bezierCurveTo(f, h, d, g, c, u);
          break;
      }
  }
  return { offsetX: i.ha * e, path: s };
}
function ul(a, e) {
  this.object = a, this.domElement = e !== void 0 ? e : document, this.enabled = !0, this.target = new j(), this.center = this.target, this.noZoom = !1, this.zoomSpeed = 1, this.minDistance = 0, this.maxDistance = 1 / 0, this.noRotate = !1, this.rotateSpeed = 1, this.noPan = !1, this.keyPanSpeed = 7, this.autoRotate = !1, this.autoRotateSpeed = 2, this.minPolarAngle = 0, this.maxPolarAngle = Math.PI, this.noKeys = !1, this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
  var t = this, r = new Ce(), n = new Ce(), i = new Ce(), s = new Ce(), o = new Ce(), l = new Ce(), c = new j(), u = new j(), f = new Ce(), h = new Ce(), d = new Ce(), g = 1, v = new j();
  new j();
  var m = {
    NONE: -1,
    ROTATE: 0,
    DOLLY: 1,
    PAN: 2,
    TOUCH_ROTATE: 3,
    TOUCH_DOLLY: 4,
    TOUCH_PAN: 5
  }, p = m.NONE;
  this.target0 = this.target.clone(), this.position0 = this.object.position.clone();
  var T = { type: "change" }, x = { type: "start" }, _ = { type: "end" };
  this.rotateLeft = function(O) {
    O === void 0 && (O = D());
  }, this.rotateUp = function(O) {
    O === void 0 && (O = D());
  }, this.panLeft = function(O) {
    var z = this.object.matrix.elements;
    c.set(z[0], z[1], z[2]), c.multiplyScalar(-O), v.add(c);
  }, this.panUp = function(O) {
    var z = this.object.matrix.elements;
    c.set(z[4], z[5], z[6]), c.multiplyScalar(O), v.add(c);
  }, this.pan = function(O, z) {
    var ne = t.domElement === document ? t.domElement.body : t.domElement;
    if (t.object.fov !== void 0) {
      var q = t.object.position, K = q.clone().sub(t.target), Z = K.length();
      Z *= Math.tan(t.object.fov / 2 * Math.PI / 180), t.panLeft(2 * O * Z / ne.clientHeight), t.panUp(2 * z * Z / ne.clientHeight);
    } else t.object.top !== void 0 ? (t.panLeft(O * (t.object.right - t.object.left) / ne.clientWidth), t.panUp(z * (t.object.top - t.object.bottom) / ne.clientHeight)) : console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
  }, this.dollyIn = function(O) {
    O === void 0 && (O = C()), g /= O;
  }, this.dollyOut = function(O) {
    O === void 0 && (O = C()), g *= O;
  }, this.update = function() {
    t.object.top !== void 0 && (this.object.top = g * this.object.top, this.object.bottom = g * this.object.bottom, this.object.left = g * this.object.left, this.object.right = g * this.object.right, this.object.updateProjectionMatrix());
    var O = this.object.position;
    u.copy(O).sub(this.target), this.target.add(v), O.copy(this.target).add(u), this.object.lookAt(this.target), this.dispatchEvent(T), g = 1, v.set(0, 0, 0);
  }, this.reset = function() {
    p = m.NONE, this.target.copy(this.target0), this.object.position.copy(this.position0), this.update();
  };
  function D() {
    return 2 * Math.PI / 60 / 60 * t.autoRotateSpeed;
  }
  function C() {
    return Math.pow(0.95, t.zoomSpeed);
  }
  function A(O) {
    if (t.enabled !== !1) {
      if (O.preventDefault(), O.button === 2) {
        if (t.noRotate === !0) return;
        p = m.ROTATE, r.set(O.clientX, O.clientY);
      } else if (O.button === 1) {
        if (t.noZoom === !0) return;
        p = m.DOLLY, f.set(O.clientX, O.clientY);
      } else if (O.button === 0) {
        if (t.noPan === !0) return;
        p = m.PAN, s.set(O.clientX, O.clientY);
      }
      t.domElement.addEventListener("mousemove", R, !1), t.domElement.addEventListener("mouseup", E, !1), t.dispatchEvent(x);
    }
  }
  function R(O) {
    if (t.enabled !== !1) {
      O.preventDefault();
      var z = t.domElement === document ? t.domElement.body : t.domElement;
      if (p === m.ROTATE) {
        if (t.noRotate === !0) return;
        n.set(O.clientX, O.clientY), i.subVectors(n, r), t.rotateLeft(2 * Math.PI * i.x / z.clientWidth * t.rotateSpeed), t.rotateUp(2 * Math.PI * i.y / z.clientHeight * t.rotateSpeed), r.copy(n);
      } else if (p === m.DOLLY) {
        if (t.noZoom === !0) return;
        h.set(O.clientX, O.clientY), d.subVectors(h, f), d.y > 0 ? t.dollyIn() : t.dollyOut(), f.copy(h);
      } else if (p === m.PAN) {
        if (t.noPan === !0) return;
        o.set(O.clientX, O.clientY), l.subVectors(o, s), t.pan(l.x, l.y), s.copy(o);
      }
      t.update();
    }
  }
  function E() {
    t.enabled !== !1 && (t.domElement.removeEventListener("mousemove", R, !1), t.domElement.removeEventListener("mouseup", E, !1), t.dispatchEvent(_), p = m.NONE);
  }
  function S(O) {
    if (!(t.enabled === !1 || t.noZoom === !0)) {
      O.preventDefault();
      var z = 0;
      O.wheelDelta !== void 0 ? z = O.wheelDelta : O.detail !== void 0 && (z = -O.detail), z > 0 ? t.dollyOut() : t.dollyIn(), t.update(), t.dispatchEvent(x), t.dispatchEvent(_);
    }
  }
  function F(O) {
    if (!(t.enabled === !1 || t.noKeys === !0 || t.noPan === !0))
      switch (O.keyCode) {
        case t.keys.UP:
          t.pan(0, t.keyPanSpeed), t.update();
          break;
        case t.keys.BOTTOM:
          t.pan(0, -t.keyPanSpeed), t.update();
          break;
        case t.keys.LEFT:
          t.pan(t.keyPanSpeed, 0), t.update();
          break;
        case t.keys.RIGHT:
          t.pan(-t.keyPanSpeed, 0), t.update();
          break;
      }
  }
  function L(O) {
    if (t.enabled !== !1) {
      switch (O.touches.length) {
        case 3:
          if (t.noRotate === !0) return;
          p = m.TOUCH_ROTATE, r.set(O.touches[0].pageX, O.touches[0].pageY);
          break;
        case 2:
          if (t.noZoom === !0) return;
          p = m.TOUCH_DOLLY;
          var z = O.touches[0].pageX - O.touches[1].pageX, ne = O.touches[0].pageY - O.touches[1].pageY, q = Math.sqrt(z * z + ne * ne);
          f.set(0, q);
          break;
        case 1:
          if (t.noPan === !0) return;
          p = m.TOUCH_PAN, s.set(O.touches[0].pageX, O.touches[0].pageY);
          break;
        default:
          p = m.NONE;
      }
      t.dispatchEvent(x);
    }
  }
  function B(O) {
    if (t.enabled !== !1) {
      O.preventDefault(), O.stopPropagation();
      var z = t.domElement === document ? t.domElement.body : t.domElement;
      switch (O.touches.length) {
        case 3:
          if (t.noRotate === !0 || p !== m.TOUCH_ROTATE) return;
          n.set(O.touches[0].pageX, O.touches[0].pageY), i.subVectors(n, r), t.rotateLeft(2 * Math.PI * i.x / z.clientWidth * t.rotateSpeed), t.rotateUp(2 * Math.PI * i.y / z.clientHeight * t.rotateSpeed), r.copy(n), t.update();
          break;
        case 2:
          if (t.noZoom === !0 || p !== m.TOUCH_DOLLY) return;
          var ne = O.touches[0].pageX - O.touches[1].pageX, q = O.touches[0].pageY - O.touches[1].pageY, K = Math.sqrt(ne * ne + q * q);
          h.set(0, K), d.subVectors(h, f), d.y > 0 ? t.dollyOut() : t.dollyIn(), f.copy(h), t.update();
          break;
        case 1:
          if (t.noPan === !0 || p !== m.TOUCH_PAN) return;
          o.set(O.touches[0].pageX, O.touches[0].pageY), l.subVectors(o, s), t.pan(l.x, l.y), s.copy(o), t.update();
          break;
        default:
          p = m.NONE;
      }
    }
  }
  function k() {
    t.enabled !== !1 && (t.dispatchEvent(_), p = m.NONE);
  }
  this.domElement.addEventListener(
    "contextmenu",
    function(O) {
      O.preventDefault();
    },
    !1
  ), this.domElement.addEventListener("mousedown", A, !1), this.domElement.addEventListener("mousewheel", S, !1), this.domElement.addEventListener("DOMMouseScroll", S, !1), this.domElement.addEventListener("touchstart", L, !1), this.domElement.addEventListener("touchend", k, !1), this.domElement.addEventListener("touchmove", B, !1), window.addEventListener("keydown", F, !1);
}
ul.prototype = Object.create(Gn.prototype);
const Cp = (a, e) => typeof e > "u" || +e == 0 ? Math.round(a) : (a = +a, e = +e, isNaN(a) || !(typeof e == "number" && e % 1 === 0) ? NaN : (a = a.toString().split("e"), a = Math.round(+(a[0] + "e" + (a[1] ? +a[1] - e : -e))), a = a.toString().split("e"), +(a[0] + "e" + (a[1] ? +a[1] + e : e)))), Rp = (a, e, t, r, n) => {
  const i = t.length, s = t[0].length;
  if (a < 0 || a > 1)
    throw new Error("t out of bounds [0,1]: " + a);
  if (e < 1) throw new Error("degree must be at least 1 (linear)");
  if (e > i - 1) throw new Error("degree must be less than or equal to point count - 1");
  if (!n) {
    n = [];
    for (let g = 0; g < i; g++)
      n[g] = 1;
  }
  if (r) {
    if (r.length !== i + e + 1) throw new Error("bad knot vector length");
  } else {
    r = [];
    for (let g = 0; g < i + e + 1; g++)
      r[g] = g;
  }
  const o = [e, r.length - 1 - e], l = r[o[0]], c = r[o[1]];
  a = a * (c - l) + l, a = Math.max(a, l), a = Math.min(a, c);
  let u;
  for (u = o[0]; u < o[1] && !(a >= r[u] && a <= r[u + 1]); u++)
    ;
  const f = [];
  for (let g = 0; g < i; g++) {
    f[g] = [];
    for (let v = 0; v < s; v++)
      f[g][v] = t[g][v] * n[g];
    f[g][s] = n[g];
  }
  let h;
  for (let g = 1; g <= e + 1; g++)
    for (let v = u; v > u - e - 1 + g; v--) {
      h = (a - r[v]) / (r[v + e + 1 - g] - r[v]);
      for (let m = 0; m < s + 1; m++)
        f[v][m] = (1 - h) * f[v - 1][m] + h * f[v][m];
    }
  const d = [];
  for (let g = 0; g < s; g++)
    d[g] = Cp(f[u][g] / f[u][s], -9);
  return d;
};
function Pp() {
  var a = /* @__PURE__ */ Object.create(null);
  function e(n, i) {
    var s = n.id, o = n.name, l = n.dependencies;
    l === void 0 && (l = []);
    var c = n.init;
    c === void 0 && (c = function() {
    });
    var u = n.getTransferables;
    if (u === void 0 && (u = null), !a[s])
      try {
        l = l.map(function(h) {
          return h && h.isWorkerModule && (e(h, function(d) {
            if (d instanceof Error)
              throw d;
          }), h = a[h.id].value), h;
        }), c = r("<" + o + ">.init", c), u && (u = r("<" + o + ">.getTransferables", u));
        var f = null;
        typeof c == "function" ? f = c.apply(void 0, l) : console.error("worker module init function failed to rehydrate"), a[s] = {
          id: s,
          value: f,
          getTransferables: u
        }, i(f);
      } catch (h) {
        h && h.noLog || console.error(h), i(h);
      }
  }
  function t(n, i) {
    var s, o = n.id, l = n.args;
    (!a[o] || typeof a[o].value != "function") && i(new Error("Worker module " + o + ": not found or its 'init' did not return a function"));
    try {
      var c = (s = a[o]).value.apply(s, l);
      c && typeof c.then == "function" ? c.then(u, function(f) {
        return i(f instanceof Error ? f : new Error("" + f));
      }) : u(c);
    } catch (f) {
      i(f);
    }
    function u(f) {
      try {
        var h = a[o].getTransferables && a[o].getTransferables(f);
        (!h || !Array.isArray(h) || !h.length) && (h = void 0), i(f, h);
      } catch (d) {
        console.error(d), i(d);
      }
    }
  }
  function r(n, i) {
    var s = void 0;
    self.troikaDefine = function(l) {
      return s = l;
    };
    var o = URL.createObjectURL(
      new Blob(
        ["/** " + n.replace(/\*/g, "") + ` **/

troikaDefine(
` + i + `
)`],
        { type: "application/javascript" }
      )
    );
    try {
      importScripts(o);
    } catch (l) {
      console.error(l);
    }
    return URL.revokeObjectURL(o), delete self.troikaDefine, s;
  }
  self.addEventListener("message", function(n) {
    var i = n.data, s = i.messageId, o = i.action, l = i.data;
    try {
      o === "registerModule" && e(l, function(c) {
        c instanceof Error ? postMessage({
          messageId: s,
          success: !1,
          error: c.message
        }) : postMessage({
          messageId: s,
          success: !0,
          result: { isCallable: typeof c == "function" }
        });
      }), o === "callModule" && t(l, function(c, u) {
        c instanceof Error ? postMessage({
          messageId: s,
          success: !1,
          error: c.message
        }) : postMessage({
          messageId: s,
          success: !0,
          result: c
        }, u || void 0);
      });
    } catch (c) {
      postMessage({
        messageId: s,
        success: !1,
        error: c.stack
      });
    }
  });
}
function Up(a) {
  var e = function() {
    for (var t = [], r = arguments.length; r--; ) t[r] = arguments[r];
    return e._getInitResult().then(function(n) {
      if (typeof n == "function")
        return n.apply(void 0, t);
      throw new Error("Worker module function was called but `init` did not return a callable function");
    });
  };
  return e._getInitResult = function() {
    var t = a.dependencies, r = a.init;
    t = Array.isArray(t) ? t.map(
      function(i) {
        return i && i._getInitResult ? i._getInitResult() : i;
      }
    ) : [];
    var n = Promise.all(t).then(function(i) {
      return r.apply(null, i);
    });
    return e._getInitResult = function() {
      return n;
    }, n;
  }, e;
}
var hl = function() {
  var a = !1;
  if (typeof window < "u" && typeof window.document < "u")
    try {
      var e = new Worker(
        URL.createObjectURL(new Blob([""], { type: "application/javascript" }))
      );
      e.terminate(), a = !0;
    } catch (t) {
      typeof process < "u" && process.env.NODE_ENV === "test" || console.log(
        "Troika createWorkerModule: web workers not allowed; falling back to main thread execution. Cause: [" + t.message + "]"
      );
    }
  return hl = function() {
    return a;
  }, a;
}, Dp = 0, Lp = 0, Ia = !1, Gi = /* @__PURE__ */ Object.create(null), zi = /* @__PURE__ */ Object.create(null), qa = /* @__PURE__ */ Object.create(null);
function xi(a) {
  if ((!a || typeof a.init != "function") && !Ia)
    throw new Error("requires `options.init` function");
  var e = a.dependencies, t = a.init, r = a.getTransferables, n = a.workerId;
  if (!hl())
    return Up(a);
  n == null && (n = "#default");
  var i = "workerModule" + ++Dp, s = a.name || i, o = null;
  e = e && e.map(function(c) {
    return typeof c == "function" && !c.workerModuleData && (Ia = !0, c = xi({
      workerId: n,
      name: "<" + s + "> function dependency: " + c.name,
      init: `function(){return (
` + Fr(c) + `
)}`
    }), Ia = !1), c && c.workerModuleData && (c = c.workerModuleData), c;
  });
  function l() {
    for (var c = [], u = arguments.length; u--; ) c[u] = arguments[u];
    if (!o) {
      o = So(n, "registerModule", l.workerModuleData);
      var f = function() {
        o = null, zi[n].delete(f);
      };
      (zi[n] || (zi[n] = /* @__PURE__ */ new Set())).add(f);
    }
    return o.then(function(h) {
      var d = h.isCallable;
      if (d)
        return So(n, "callModule", { id: i, args: c });
      throw new Error("Worker module function was called but `init` did not return a callable function");
    });
  }
  return l.workerModuleData = {
    isWorkerModule: !0,
    id: i,
    name: s,
    dependencies: e,
    init: Fr(t),
    getTransferables: r && Fr(r)
  }, l;
}
function Fp(a) {
  zi[a] && zi[a].forEach(function(e) {
    e();
  }), Gi[a] && (Gi[a].terminate(), delete Gi[a]);
}
function Fr(a) {
  var e = a.toString();
  return !/^function/.test(e) && /^\w+\s*\(/.test(e) && (e = "function " + e), e;
}
function Ip(a) {
  var e = Gi[a];
  if (!e) {
    var t = Fr(Pp);
    e = Gi[a] = new Worker(
      URL.createObjectURL(
        new Blob(
          ["/** Worker Module Bootstrap: " + a.replace(/\*/g, "") + ` **/

;(` + t + ")()"],
          { type: "application/javascript" }
        )
      )
    ), e.onmessage = function(r) {
      var n = r.data, i = n.messageId, s = qa[i];
      if (!s)
        throw new Error("WorkerModule response with empty or unknown messageId");
      delete qa[i], s(n);
    };
  }
  return e;
}
function So(a, e, t) {
  return new Promise(function(r, n) {
    var i = ++Lp;
    qa[i] = function(s) {
      s.success ? r(s.result) : n(new Error("Error in worker " + e + " call: " + s.error));
    }, Ip(a).postMessage({
      messageId: i,
      action: e,
      data: t
    });
  });
}
function fl() {
  var a = function(e) {
    function t(K, Z, N, Y, ie, b, U, G) {
      var I = 1 - U;
      G.x = I * I * K + 2 * I * U * N + U * U * ie, G.y = I * I * Z + 2 * I * U * Y + U * U * b;
    }
    function r(K, Z, N, Y, ie, b, U, G, I, V) {
      var re = 1 - I;
      V.x = re * re * re * K + 3 * re * re * I * N + 3 * re * I * I * ie + I * I * I * U, V.y = re * re * re * Z + 3 * re * re * I * Y + 3 * re * I * I * b + I * I * I * G;
    }
    function n(K, Z) {
      for (var N = /([MLQCZ])([^MLQCZ]*)/g, Y, ie, b, U, G; Y = N.exec(K); ) {
        var I = Y[2].replace(/^\s*|\s*$/g, "").split(/[,\s]+/).map(function(V) {
          return parseFloat(V);
        });
        switch (Y[1]) {
          case "M":
            U = ie = I[0], G = b = I[1];
            break;
          case "L":
            (I[0] !== U || I[1] !== G) && Z("L", U, G, U = I[0], G = I[1]);
            break;
          case "Q": {
            Z("Q", U, G, U = I[2], G = I[3], I[0], I[1]);
            break;
          }
          case "C": {
            Z("C", U, G, U = I[4], G = I[5], I[0], I[1], I[2], I[3]);
            break;
          }
          case "Z":
            (U !== ie || G !== b) && Z("L", U, G, ie, b);
            break;
        }
      }
    }
    function i(K, Z, N) {
      N === void 0 && (N = 16);
      var Y = { x: 0, y: 0 };
      n(K, function(ie, b, U, G, I, V, re, he, fe) {
        switch (ie) {
          case "L":
            Z(b, U, G, I);
            break;
          case "Q": {
            for (var W = b, ce = U, P = 1; P < N; P++)
              t(
                b,
                U,
                V,
                re,
                G,
                I,
                P / (N - 1),
                Y
              ), Z(W, ce, Y.x, Y.y), W = Y.x, ce = Y.y;
            break;
          }
          case "C": {
            for (var pe = b, ae = U, ve = 1; ve < N; ve++)
              r(
                b,
                U,
                V,
                re,
                he,
                fe,
                G,
                I,
                ve / (N - 1),
                Y
              ), Z(pe, ae, Y.x, Y.y), pe = Y.x, ae = Y.y;
            break;
          }
        }
      });
    }
    var s = "precision highp float;attribute vec2 aUV;varying vec2 vUV;void main(){vUV=aUV;gl_Position=vec4(mix(vec2(-1.0),vec2(1.0),aUV),0.0,1.0);}", o = "precision highp float;uniform sampler2D tex;varying vec2 vUV;void main(){gl_FragColor=texture2D(tex,vUV);}", l = /* @__PURE__ */ new WeakMap(), c = {
      premultipliedAlpha: !1,
      preserveDrawingBuffer: !0,
      antialias: !1,
      depth: !1
    };
    function u(K, Z) {
      var N = K.getContext ? K.getContext("webgl", c) : K, Y = l.get(N);
      if (!Y) {
        let re = function(pe) {
          var ae = b[pe];
          if (!ae && (ae = b[pe] = N.getExtension(pe), !ae))
            throw new Error(pe + " not supported");
          return ae;
        }, he = function(pe, ae) {
          var ve = N.createShader(ae);
          return N.shaderSource(ve, pe), N.compileShader(ve), ve;
        }, fe = function(pe, ae, ve, te) {
          if (!U[pe]) {
            var Te = {}, me = {}, M = N.createProgram();
            N.attachShader(M, he(ae, N.VERTEX_SHADER)), N.attachShader(M, he(ve, N.FRAGMENT_SHADER)), N.linkProgram(M), U[pe] = {
              program: M,
              transaction: function(H) {
                N.useProgram(M), H({
                  setUniform: function(ee, oe) {
                    for (var Se = [], de = arguments.length - 2; de-- > 0; ) Se[de] = arguments[de + 2];
                    var xe = me[oe] || (me[oe] = N.getUniformLocation(M, oe));
                    N["uniform" + ee].apply(N, [xe].concat(Se));
                  },
                  setAttribute: function(ee, oe, Se, de, xe) {
                    var De = Te[ee];
                    De || (De = Te[ee] = {
                      buf: N.createBuffer(),
                      // TODO should we destroy our buffers?
                      loc: N.getAttribLocation(M, ee),
                      data: null
                    }), N.bindBuffer(N.ARRAY_BUFFER, De.buf), N.vertexAttribPointer(De.loc, oe, N.FLOAT, !1, 0, 0), N.enableVertexAttribArray(De.loc), ie ? N.vertexAttribDivisor(De.loc, de) : re("ANGLE_instanced_arrays").vertexAttribDivisorANGLE(De.loc, de), xe !== De.data && (N.bufferData(N.ARRAY_BUFFER, xe, Se), De.data = xe);
                  }
                });
              }
            };
          }
          U[pe].transaction(te);
        }, W = function(pe, ae) {
          I++;
          try {
            N.activeTexture(N.TEXTURE0 + I);
            var ve = G[pe];
            ve || (ve = G[pe] = N.createTexture(), N.bindTexture(N.TEXTURE_2D, ve), N.texParameteri(N.TEXTURE_2D, N.TEXTURE_MIN_FILTER, N.NEAREST), N.texParameteri(N.TEXTURE_2D, N.TEXTURE_MAG_FILTER, N.NEAREST)), N.bindTexture(N.TEXTURE_2D, ve), ae(ve, I);
          } finally {
            I--;
          }
        }, ce = function(pe, ae, ve) {
          var te = N.createFramebuffer();
          V.push(te), N.bindFramebuffer(N.FRAMEBUFFER, te), N.activeTexture(N.TEXTURE0 + ae), N.bindTexture(N.TEXTURE_2D, pe), N.framebufferTexture2D(N.FRAMEBUFFER, N.COLOR_ATTACHMENT0, N.TEXTURE_2D, pe, 0);
          try {
            ve(te);
          } finally {
            N.deleteFramebuffer(te), N.bindFramebuffer(N.FRAMEBUFFER, V[--V.length - 1] || null);
          }
        }, P = function() {
          b = {}, U = {}, G = {}, I = -1, V.length = 0;
        };
        var ie = typeof WebGL2RenderingContext < "u" && N instanceof WebGL2RenderingContext, b = {}, U = {}, G = {}, I = -1, V = [];
        N.canvas.addEventListener("webglcontextlost", function(pe) {
          P(), pe.preventDefault();
        }, !1), l.set(N, Y = {
          gl: N,
          isWebGL2: ie,
          getExtension: re,
          withProgram: fe,
          withTexture: W,
          withTextureFramebuffer: ce,
          handleContextLoss: P
        });
      }
      Z(Y);
    }
    function f(K, Z, N, Y, ie, b, U, G) {
      U === void 0 && (U = 15), G === void 0 && (G = null), u(K, function(I) {
        var V = I.gl, re = I.withProgram, he = I.withTexture;
        he("copy", function(fe, W) {
          V.texImage2D(V.TEXTURE_2D, 0, V.RGBA, ie, b, 0, V.RGBA, V.UNSIGNED_BYTE, Z), re("copy", s, o, function(ce) {
            var P = ce.setUniform, pe = ce.setAttribute;
            pe("aUV", 2, V.STATIC_DRAW, 0, new Float32Array([0, 0, 2, 0, 0, 2])), P("1i", "image", W), V.bindFramebuffer(V.FRAMEBUFFER, G || null), V.disable(V.BLEND), V.colorMask(U & 8, U & 4, U & 2, U & 1), V.viewport(N, Y, ie, b), V.scissor(N, Y, ie, b), V.drawArrays(V.TRIANGLES, 0, 3);
          });
        });
      });
    }
    function h(K, Z, N) {
      var Y = K.width, ie = K.height;
      u(K, function(b) {
        var U = b.gl, G = new Uint8Array(Y * ie * 4);
        U.readPixels(0, 0, Y, ie, U.RGBA, U.UNSIGNED_BYTE, G), K.width = Z, K.height = N, f(U, G, 0, 0, Y, ie);
      });
    }
    var d = /* @__PURE__ */ Object.freeze({
      __proto__: null,
      withWebGLContext: u,
      renderImageData: f,
      resizeWebGLCanvasWithoutClearing: h
    });
    function g(K, Z, N, Y, ie, b) {
      b === void 0 && (b = 1);
      var U = new Uint8Array(K * Z), G = Y[2] - Y[0], I = Y[3] - Y[1], V = [];
      i(N, function(pe, ae, ve, te) {
        V.push({
          x1: pe,
          y1: ae,
          x2: ve,
          y2: te,
          minX: Math.min(pe, ve),
          minY: Math.min(ae, te),
          maxX: Math.max(pe, ve),
          maxY: Math.max(ae, te)
        });
      }), V.sort(function(pe, ae) {
        return pe.maxX - ae.maxX;
      });
      for (var re = 0; re < K; re++)
        for (var he = 0; he < Z; he++) {
          var fe = ce(
            Y[0] + G * (re + 0.5) / K,
            Y[1] + I * (he + 0.5) / Z
          ), W = Math.pow(1 - Math.abs(fe) / ie, b) / 2;
          fe < 0 && (W = 1 - W), W = Math.max(0, Math.min(255, Math.round(W * 255))), U[he * K + re] = W;
        }
      return U;
      function ce(pe, ae) {
        for (var ve = 1 / 0, te = 1 / 0, Te = V.length; Te--; ) {
          var me = V[Te];
          if (me.maxX + te <= pe)
            break;
          if (pe + te > me.minX && ae - te < me.maxY && ae + te > me.minY) {
            var M = p(pe, ae, me.x1, me.y1, me.x2, me.y2);
            M < ve && (ve = M, te = Math.sqrt(ve));
          }
        }
        return P(pe, ae) && (te = -te), te;
      }
      function P(pe, ae) {
        for (var ve = 0, te = V.length; te--; ) {
          var Te = V[te];
          if (Te.maxX <= pe)
            break;
          var me = Te.y1 > ae != Te.y2 > ae && pe < (Te.x2 - Te.x1) * (ae - Te.y1) / (Te.y2 - Te.y1) + Te.x1;
          me && (ve += Te.y1 < Te.y2 ? 1 : -1);
        }
        return ve !== 0;
      }
    }
    function v(K, Z, N, Y, ie, b, U, G, I, V) {
      b === void 0 && (b = 1), G === void 0 && (G = 0), I === void 0 && (I = 0), V === void 0 && (V = 0), m(K, Z, N, Y, ie, b, U, null, G, I, V);
    }
    function m(K, Z, N, Y, ie, b, U, G, I, V, re) {
      b === void 0 && (b = 1), I === void 0 && (I = 0), V === void 0 && (V = 0), re === void 0 && (re = 0);
      for (var he = g(K, Z, N, Y, ie, b), fe = new Uint8Array(he.length * 4), W = 0; W < he.length; W++)
        fe[W * 4 + re] = he[W];
      f(U, fe, I, V, K, Z, 1 << 3 - re, G);
    }
    function p(K, Z, N, Y, ie, b) {
      var U = ie - N, G = b - Y, I = U * U + G * G, V = I ? Math.max(0, Math.min(1, ((K - N) * U + (Z - Y) * G) / I)) : 0, re = K - (N + V * U), he = Z - (Y + V * G);
      return re * re + he * he;
    }
    var T = /* @__PURE__ */ Object.freeze({
      __proto__: null,
      generate: g,
      generateIntoCanvas: v,
      generateIntoFramebuffer: m
    }), x = "precision highp float;uniform vec4 uGlyphBounds;attribute vec2 aUV;attribute vec4 aLineSegment;varying vec4 vLineSegment;varying vec2 vGlyphXY;void main(){vLineSegment=aLineSegment;vGlyphXY=mix(uGlyphBounds.xy,uGlyphBounds.zw,aUV);gl_Position=vec4(mix(vec2(-1.0),vec2(1.0),aUV),0.0,1.0);}", _ = "precision highp float;uniform vec4 uGlyphBounds;uniform float uMaxDistance;uniform float uExponent;varying vec4 vLineSegment;varying vec2 vGlyphXY;float absDistToSegment(vec2 point,vec2 lineA,vec2 lineB){vec2 lineDir=lineB-lineA;float lenSq=dot(lineDir,lineDir);float t=lenSq==0.0 ? 0.0 : clamp(dot(point-lineA,lineDir)/lenSq,0.0,1.0);vec2 linePt=lineA+t*lineDir;return distance(point,linePt);}void main(){vec4 seg=vLineSegment;vec2 p=vGlyphXY;float dist=absDistToSegment(p,seg.xy,seg.zw);float val=pow(1.0-clamp(dist/uMaxDistance,0.0,1.0),uExponent)*0.5;bool crossing=(seg.y>p.y!=seg.w>p.y)&&(p.x<(seg.z-seg.x)*(p.y-seg.y)/(seg.w-seg.y)+seg.x);bool crossingUp=crossing&&vLineSegment.y<vLineSegment.w;gl_FragColor=vec4(crossingUp ? 1.0/255.0 : 0.0,crossing&&!crossingUp ? 1.0/255.0 : 0.0,0.0,val);}", D = "precision highp float;uniform sampler2D tex;varying vec2 vUV;void main(){vec4 color=texture2D(tex,vUV);bool inside=color.r!=color.g;float val=inside ? 1.0-color.a : color.a;gl_FragColor=vec4(val);}", C = new Float32Array([0, 0, 2, 0, 0, 2]), A = null, R = !1, E = {}, S = /* @__PURE__ */ new WeakMap();
    function F(K) {
      if (!R && !O(K))
        throw new Error("WebGL generation not supported");
    }
    function L(K, Z, N, Y, ie, b, U) {
      if (b === void 0 && (b = 1), U === void 0 && (U = null), !U && (U = A, !U)) {
        var G = typeof OffscreenCanvas == "function" ? new OffscreenCanvas(1, 1) : typeof document < "u" ? document.createElement("canvas") : null;
        if (!G)
          throw new Error("OffscreenCanvas or DOM canvas not supported");
        U = A = G.getContext("webgl", { depth: !1 });
      }
      F(U);
      var I = new Uint8Array(K * Z * 4);
      u(U, function(fe) {
        var W = fe.gl, ce = fe.withTexture, P = fe.withTextureFramebuffer;
        ce("readable", function(pe, ae) {
          W.texImage2D(W.TEXTURE_2D, 0, W.RGBA, K, Z, 0, W.RGBA, W.UNSIGNED_BYTE, null), P(pe, ae, function(ve) {
            k(
              K,
              Z,
              N,
              Y,
              ie,
              b,
              W,
              ve,
              0,
              0,
              0
              // red channel
            ), W.readPixels(0, 0, K, Z, W.RGBA, W.UNSIGNED_BYTE, I);
          });
        });
      });
      for (var V = new Uint8Array(K * Z), re = 0, he = 0; re < I.length; re += 4)
        V[he++] = I[re];
      return V;
    }
    function B(K, Z, N, Y, ie, b, U, G, I, V) {
      b === void 0 && (b = 1), G === void 0 && (G = 0), I === void 0 && (I = 0), V === void 0 && (V = 0), k(K, Z, N, Y, ie, b, U, null, G, I, V);
    }
    function k(K, Z, N, Y, ie, b, U, G, I, V, re) {
      b === void 0 && (b = 1), I === void 0 && (I = 0), V === void 0 && (V = 0), re === void 0 && (re = 0), F(U);
      var he = [];
      i(N, function(fe, W, ce, P) {
        he.push(fe, W, ce, P);
      }), he = new Float32Array(he), u(U, function(fe) {
        var W = fe.gl, ce = fe.isWebGL2, P = fe.getExtension, pe = fe.withProgram, ae = fe.withTexture, ve = fe.withTextureFramebuffer, te = fe.handleContextLoss;
        if (ae("rawDistances", function(Te, me) {
          (K !== Te._lastWidth || Z !== Te._lastHeight) && W.texImage2D(
            W.TEXTURE_2D,
            0,
            W.RGBA,
            Te._lastWidth = K,
            Te._lastHeight = Z,
            0,
            W.RGBA,
            W.UNSIGNED_BYTE,
            null
          ), pe("main", x, _, function(M) {
            var y = M.setAttribute, H = M.setUniform, $ = !ce && P("ANGLE_instanced_arrays"), ee = !ce && P("EXT_blend_minmax");
            y("aUV", 2, W.STATIC_DRAW, 0, C), y("aLineSegment", 4, W.DYNAMIC_DRAW, 1, he), H.apply(void 0, ["4f", "uGlyphBounds"].concat(Y)), H("1f", "uMaxDistance", ie), H("1f", "uExponent", b), ve(Te, me, function(oe) {
              W.enable(W.BLEND), W.colorMask(!0, !0, !0, !0), W.viewport(0, 0, K, Z), W.scissor(0, 0, K, Z), W.blendFunc(W.ONE, W.ONE), W.blendEquationSeparate(W.FUNC_ADD, ce ? W.MAX : ee.MAX_EXT), W.clear(W.COLOR_BUFFER_BIT), ce ? W.drawArraysInstanced(W.TRIANGLES, 0, 3, he.length / 4) : $.drawArraysInstancedANGLE(W.TRIANGLES, 0, 3, he.length / 4);
            });
          }), pe("post", s, D, function(M) {
            M.setAttribute("aUV", 2, W.STATIC_DRAW, 0, C), M.setUniform("1i", "tex", me), W.bindFramebuffer(W.FRAMEBUFFER, G), W.disable(W.BLEND), W.colorMask(re === 0, re === 1, re === 2, re === 3), W.viewport(I, V, K, Z), W.scissor(I, V, K, Z), W.drawArrays(W.TRIANGLES, 0, 3);
          });
        }), W.isContextLost())
          throw te(), new Error("webgl context lost");
      });
    }
    function O(K) {
      var Z = !K || K === A ? E : K.canvas || K, N = S.get(Z);
      if (N === void 0) {
        R = !0;
        var Y = null;
        try {
          var ie = [
            97,
            106,
            97,
            61,
            99,
            137,
            118,
            80,
            80,
            118,
            137,
            99,
            61,
            97,
            106,
            97
          ], b = L(
            4,
            4,
            "M8,8L16,8L24,24L16,24Z",
            [0, 0, 32, 32],
            24,
            1,
            K
          );
          N = b && ie.length === b.length && b.every(function(U, G) {
            return U === ie[G];
          }), N || (Y = "bad trial run results", console.info(ie, b));
        } catch (U) {
          N = !1, Y = U.message;
        }
        Y && console.warn("WebGL SDF generation not supported:", Y), R = !1, S.set(Z, N);
      }
      return N;
    }
    var z = /* @__PURE__ */ Object.freeze({
      __proto__: null,
      generate: L,
      generateIntoCanvas: B,
      generateIntoFramebuffer: k,
      isSupported: O
    });
    function ne(K, Z, N, Y, ie, b) {
      ie === void 0 && (ie = Math.max(Y[2] - Y[0], Y[3] - Y[1]) / 2), b === void 0 && (b = 1);
      try {
        return L.apply(z, arguments);
      } catch (U) {
        return console.info("WebGL SDF generation failed, falling back to JS", U), g.apply(T, arguments);
      }
    }
    function q(K, Z, N, Y, ie, b, U, G, I, V) {
      ie === void 0 && (ie = Math.max(Y[2] - Y[0], Y[3] - Y[1]) / 2), b === void 0 && (b = 1), G === void 0 && (G = 0), I === void 0 && (I = 0), V === void 0 && (V = 0);
      try {
        return B.apply(z, arguments);
      } catch (re) {
        return console.info("WebGL SDF generation failed, falling back to JS", re), v.apply(T, arguments);
      }
    }
    return e.forEachPathCommand = n, e.generate = ne, e.generateIntoCanvas = q, e.javascript = T, e.pathToLineSegments = i, e.webgl = z, e.webglUtils = d, Object.defineProperty(e, "__esModule", { value: !0 }), e;
  }({});
  return a;
}
function Np() {
  var a = function(e) {
    var t = {
      R: "13k,1a,2,3,3,2+1j,ch+16,a+1,5+2,2+n,5,a,4,6+16,4+3,h+1b,4mo,179q,2+9,2+11,2i9+7y,2+68,4,3+4,5+13,4+3,2+4k,3+29,8+cf,1t+7z,w+17,3+3m,1t+3z,16o1+5r,8+30,8+mc,29+1r,29+4v,75+73",
      EN: "1c+9,3d+1,6,187+9,513,4+5,7+9,sf+j,175h+9,qw+q,161f+1d,4xt+a,25i+9",
      ES: "17,2,6dp+1,f+1,av,16vr,mx+1,4o,2",
      ET: "z+2,3h+3,b+1,ym,3e+1,2o,p4+1,8,6u,7c,g6,1wc,1n9+4,30+1b,2n,6d,qhx+1,h0m,a+1,49+2,63+1,4+1,6bb+3,12jj",
      AN: "16o+5,2j+9,2+1,35,ed,1ff2+9,87+u",
      CS: "18,2+1,b,2u,12k,55v,l,17v0,2,3,53,2+1,b",
      B: "a,3,f+2,2v,690",
      S: "9,2,k",
      WS: "c,k,4f4,1vk+a,u,1j,335",
      ON: "x+1,4+4,h+5,r+5,r+3,z,5+3,2+1,2+1,5,2+2,3+4,o,w,ci+1,8+d,3+d,6+8,2+g,39+1,9,6+1,2,33,b8,3+1,3c+1,7+1,5r,b,7h+3,sa+5,2,3i+6,jg+3,ur+9,2v,ij+1,9g+9,7+a,8m,4+1,49+x,14u,2+2,c+2,e+2,e+2,e+1,i+n,e+e,2+p,u+2,e+2,36+1,2+3,2+1,b,2+2,6+5,2,2,2,h+1,5+4,6+3,3+f,16+2,5+3l,3+81,1y+p,2+40,q+a,m+13,2r+ch,2+9e,75+hf,3+v,2+2w,6e+5,f+6,75+2a,1a+p,2+2g,d+5x,r+b,6+3,4+o,g,6+1,6+2,2k+1,4,2j,5h+z,1m+1,1e+f,t+2,1f+e,d+3,4o+3,2s+1,w,535+1r,h3l+1i,93+2,2s,b+1,3l+x,2v,4g+3,21+3,kz+1,g5v+1,5a,j+9,n+v,2,3,2+8,2+1,3+2,2,3,46+1,4+4,h+5,r+5,r+a,3h+2,4+6,b+4,78,1r+24,4+c,4,1hb,ey+6,103+j,16j+c,1ux+7,5+g,fsh,jdq+1t,4,57+2e,p1,1m,1m,1m,1m,4kt+1,7j+17,5+2r,d+e,3+e,2+e,2+10,m+4,w,1n+5,1q,4z+5,4b+rb,9+c,4+c,4+37,d+2g,8+b,l+b,5+1j,9+9,7+13,9+t,3+1,27+3c,2+29,2+3q,d+d,3+4,4+2,6+6,a+o,8+6,a+2,e+6,16+42,2+1i",
      BN: "0+8,6+d,2s+5,2+p,e,4m9,1kt+2,2b+5,5+5,17q9+v,7k,6p+8,6+1,119d+3,440+7,96s+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+75,6p+2rz,1ben+1,1ekf+1,1ekf+1",
      NSM: "lc+33,7o+6,7c+18,2,2+1,2+1,2,21+a,1d+k,h,2u+6,3+5,3+1,2+3,10,v+q,2k+a,1n+8,a,p+3,2+8,2+2,2+4,18+2,3c+e,2+v,1k,2,5+7,5,4+6,b+1,u,1n,5+3,9,l+1,r,3+1,1m,5+1,5+1,3+2,4,v+1,4,c+1,1m,5+4,2+1,5,l+1,n+5,2,1n,3,2+3,9,8+1,c+1,v,1q,d,1f,4,1m+2,6+2,2+3,8+1,c+1,u,1n,g+1,l+1,t+1,1m+1,5+3,9,l+1,u,21,8+2,2,2j,3+6,d+7,2r,3+8,c+5,23+1,s,2,2,1k+d,2+4,2+1,6+a,2+z,a,2v+3,2+5,2+1,3+1,q+1,5+2,h+3,e,3+1,7,g,jk+2,qb+2,u+2,u+1,v+1,1t+1,2+6,9,3+a,a,1a+2,3c+1,z,3b+2,5+1,a,7+2,64+1,3,1n,2+6,2,2,3+7,7+9,3,1d+g,1s+3,1d,2+4,2,6,15+8,d+1,x+3,3+1,2+2,1l,2+1,4,2+2,1n+7,3+1,49+2,2+c,2+6,5,7,4+1,5j+1l,2+4,k1+w,2db+2,3y,2p+v,ff+3,30+1,n9x+3,2+9,x+1,29+1,7l,4,5,q+1,6,48+1,r+h,e,13+7,q+a,1b+2,1d,3+3,3+1,14,1w+5,3+1,3+1,d,9,1c,1g,2+2,3+1,6+1,2,17+1,9,6n,3,5,fn5,ki+f,h+f,r2,6b,46+4,1af+2,2+1,6+3,15+2,5,4m+1,fy+3,as+1,4a+a,4x,1j+e,1l+2,1e+3,3+1,1y+2,11+4,2+7,1r,d+1,1h+8,b+3,3,2o+2,3,2+1,7,4h,4+7,m+1,1m+1,4,12+6,4+4,5g+7,3+2,2,o,2d+5,2,5+1,2+1,6n+3,7+1,2+1,s+1,2e+7,3,2+1,2z,2,3+5,2,2u+2,3+3,2+4,78+8,2+1,75+1,2,5,41+3,3+1,5,x+5,3+1,15+5,3+3,9,a+5,3+2,1b+c,2+1,bb+6,2+5,2d+l,3+6,2+1,2+1,3f+5,4,2+1,2+6,2,21+1,4,2,9o+1,f0c+4,1o+6,t5,1s+3,2a,f5l+1,43t+2,i+7,3+6,v+3,45+2,1j0+1i,5+1d,9,f,n+4,2+e,11t+6,2+g,3+6,2+1,2+4,7a+6,c6+3,15t+6,32+6,gzhy+6n",
      AL: "16w,3,2,e+1b,z+2,2+2s,g+1,8+1,b+m,2+t,s+2i,c+e,4h+f,1d+1e,1bwe+dp,3+3z,x+c,2+1,35+3y,2rm+z,5+7,b+5,dt+l,c+u,17nl+27,1t+27,4x+6n,3+d",
      LRO: "6ct",
      RLO: "6cu",
      LRE: "6cq",
      RLE: "6cr",
      PDF: "6cs",
      LRI: "6ee",
      RLI: "6ef",
      FSI: "6eg",
      PDI: "6eh"
    }, r = {}, n = {};
    r.L = 1, n[1] = "L", Object.keys(t).forEach(function(te, Te) {
      r[te] = 1 << Te + 1, n[r[te]] = te;
    }), Object.freeze(r);
    var i = r.LRI | r.RLI | r.FSI, s = r.L | r.R | r.AL, o = r.B | r.S | r.WS | r.ON | r.FSI | r.LRI | r.RLI | r.PDI, l = r.BN | r.RLE | r.LRE | r.RLO | r.LRO | r.PDF, c = r.S | r.WS | r.B | i | r.PDI | l, u = null;
    function f() {
      if (!u) {
        u = /* @__PURE__ */ new Map();
        var te = function(me) {
          if (t.hasOwnProperty(me)) {
            var M = 0;
            t[me].split(",").forEach(function(y) {
              var H = y.split("+"), $ = H[0], ee = H[1];
              $ = parseInt($, 36), ee = ee ? parseInt(ee, 36) : 0, u.set(M += $, r[me]);
              for (var oe = 0; oe < ee; oe++)
                u.set(++M, r[me]);
            });
          }
        };
        for (var Te in t) te(Te);
      }
    }
    function h(te) {
      return f(), u.get(te.codePointAt(0)) || r.L;
    }
    function d(te) {
      return n[h(te)];
    }
    var g = {
      pairs: "14>1,1e>2,u>2,2wt>1,1>1,1ge>1,1wp>1,1j>1,f>1,hm>1,1>1,u>1,u6>1,1>1,+5,28>1,w>1,1>1,+3,b8>1,1>1,+3,1>3,-1>-1,3>1,1>1,+2,1s>1,1>1,x>1,th>1,1>1,+2,db>1,1>1,+3,3>1,1>1,+2,14qm>1,1>1,+1,4q>1,1e>2,u>2,2>1,+1",
      canonical: "6f1>-6dx,6dy>-6dx,6ec>-6ed,6ee>-6ed,6ww>2jj,-2ji>2jj,14r4>-1e7l,1e7m>-1e7l,1e7m>-1e5c,1e5d>-1e5b,1e5c>-14qx,14qy>-14qx,14vn>-1ecg,1ech>-1ecg,1edu>-1ecg,1eci>-1ecg,1eda>-1ecg,1eci>-1ecg,1eci>-168q,168r>-168q,168s>-14ye,14yf>-14ye"
    };
    function v(te, Te) {
      var me = 36, M = 0, y = /* @__PURE__ */ new Map(), H = Te && /* @__PURE__ */ new Map(), $;
      return te.split(",").forEach(function ee(oe) {
        if (oe.indexOf("+") !== -1)
          for (var Se = +oe; Se--; )
            ee($);
        else {
          $ = oe;
          var de = oe.split(">"), xe = de[0], De = de[1];
          xe = String.fromCodePoint(M += parseInt(xe, me)), De = String.fromCodePoint(M += parseInt(De, me)), y.set(xe, De), Te && H.set(De, xe);
        }
      }), { map: y, reverseMap: H };
    }
    var m, p, T;
    function x() {
      if (!m) {
        var te = v(g.pairs, !0), Te = te.map, me = te.reverseMap;
        m = Te, p = me, T = v(g.canonical, !1).map;
      }
    }
    function _(te) {
      return x(), m.get(te) || null;
    }
    function D(te) {
      return x(), p.get(te) || null;
    }
    function C(te) {
      return x(), T.get(te) || null;
    }
    var A = r.L, R = r.R, E = r.EN, S = r.ES, F = r.ET, L = r.AN, B = r.CS, k = r.B, O = r.S, z = r.ON, ne = r.BN, q = r.NSM, K = r.AL, Z = r.LRO, N = r.RLO, Y = r.LRE, ie = r.RLE, b = r.PDF, U = r.LRI, G = r.RLI, I = r.FSI, V = r.PDI;
    function re(te, Te) {
      for (var me = 125, M = new Uint32Array(te.length), y = 0; y < te.length; y++)
        M[y] = h(te[y]);
      var H = /* @__PURE__ */ new Map();
      function $(Lt, jt) {
        var Ft = M[Lt];
        M[Lt] = jt, H.set(Ft, H.get(Ft) - 1), Ft & o && H.set(o, H.get(o) - 1), H.set(jt, (H.get(jt) || 0) + 1), jt & o && H.set(o, (H.get(o) || 0) + 1);
      }
      for (var ee = new Uint8Array(te.length), oe = /* @__PURE__ */ new Map(), Se = [], de = null, xe = 0; xe < te.length; xe++)
        de || Se.push(de = {
          start: xe,
          end: te.length - 1,
          // 3.3.1 P2-P3: Determine the paragraph level
          level: Te === "rtl" ? 1 : Te === "ltr" ? 0 : gs(xe, !1)
        }), M[xe] & k && (de.end = xe, de = null);
      for (var De = ie | Y | N | Z | i | V | b | k, ye = function(Lt) {
        return Lt + (Lt & 1 ? 1 : 2);
      }, Re = function(Lt) {
        return Lt + (Lt & 1 ? 2 : 1);
      }, Pe = 0; Pe < Se.length; Pe++) {
        de = Se[Pe];
        var Ue = [{
          _level: de.level,
          _override: 0,
          //0=neutral, 1=L, 2=R
          _isolate: 0
          //bool
        }], Me = void 0, ze = 0, Fe = 0, je = 0;
        H.clear();
        for (var X = de.start; X <= de.end; X++) {
          var _e = M[X];
          if (Me = Ue[Ue.length - 1], H.set(_e, (H.get(_e) || 0) + 1), _e & o && H.set(o, (H.get(o) || 0) + 1), _e & De)
            if (_e & (ie | Y)) {
              ee[X] = Me._level;
              var se = (_e === ie ? Re : ye)(Me._level);
              se <= me && !ze && !Fe ? Ue.push({
                _level: se,
                _override: 0,
                _isolate: 0
              }) : ze || Fe++;
            } else if (_e & (N | Z)) {
              ee[X] = Me._level;
              var Ee = (_e === N ? Re : ye)(Me._level);
              Ee <= me && !ze && !Fe ? Ue.push({
                _level: Ee,
                _override: _e & N ? R : A,
                _isolate: 0
              }) : ze || Fe++;
            } else if (_e & i) {
              _e & I && (_e = gs(X + 1, !0) === 1 ? G : U), ee[X] = Me._level, Me._override && $(X, Me._override);
              var Ae = (_e === G ? Re : ye)(Me._level);
              Ae <= me && ze === 0 && Fe === 0 ? (je++, Ue.push({
                _level: Ae,
                _override: 0,
                _isolate: 1,
                _isolInitIndex: X
              })) : ze++;
            } else if (_e & V) {
              if (ze > 0)
                ze--;
              else if (je > 0) {
                for (Fe = 0; !Ue[Ue.length - 1]._isolate; )
                  Ue.pop();
                var be = Ue[Ue.length - 1]._isolInitIndex;
                be != null && (oe.set(be, X), oe.set(X, be)), Ue.pop(), je--;
              }
              Me = Ue[Ue.length - 1], ee[X] = Me._level, Me._override && $(X, Me._override);
            } else _e & b ? (ze === 0 && (Fe > 0 ? Fe-- : !Me._isolate && Ue.length > 1 && (Ue.pop(), Me = Ue[Ue.length - 1])), ee[X] = Me._level) : _e & k && (ee[X] = de.level);
          else
            ee[X] = Me._level, Me._override && _e !== ne && $(X, Me._override);
        }
        for (var Ne = [], We = null, Ge = de.start; Ge <= de.end; Ge++) {
          var Ve = M[Ge];
          if (!(Ve & l)) {
            var rt = ee[Ge], at = Ve & i, ct = Ve === V;
            We && rt === We._level ? (We._end = Ge, We._endsWithIsolInit = at) : Ne.push(We = {
              _start: Ge,
              _end: Ge,
              _level: rt,
              _startsWithPDI: ct,
              _endsWithIsolInit: at
            });
          }
        }
        for (var Ct = [], yt = 0; yt < Ne.length; yt++) {
          var Ot = Ne[yt];
          if (!Ot._startsWithPDI || Ot._startsWithPDI && !oe.has(Ot._start)) {
            for (var qt = [We = Ot], nn = void 0; We && We._endsWithIsolInit && (nn = oe.get(We._end)) != null; )
              for (var Rt = yt + 1; Rt < Ne.length; Rt++)
                if (Ne[Rt]._start === nn) {
                  qt.push(We = Ne[Rt]);
                  break;
                }
            for (var pt = [], Ht = 0; Ht < qt.length; Ht++)
              for (var Si = qt[Ht], Vn = Si._start; Vn <= Si._end; Vn++)
                pt.push(Vn);
            for (var Xr = ee[pt[0]], ji = de.level, Hn = pt[0] - 1; Hn >= 0; Hn--)
              if (!(M[Hn] & l)) {
                ji = ee[Hn];
                break;
              }
            var w = pt[pt.length - 1], Q = ee[w], ue = de.level;
            if (!(M[w] & i)) {
              for (var le = w + 1; le <= de.end; le++)
                if (!(M[le] & l)) {
                  ue = ee[le];
                  break;
                }
            }
            Ct.push({
              _seqIndices: pt,
              _sosType: Math.max(ji, Xr) % 2 ? R : A,
              _eosType: Math.max(ue, Q) % 2 ? R : A
            });
          }
        }
        for (var J = 0; J < Ct.length; J++) {
          var we = Ct[J], ge = we._seqIndices, Ie = we._sosType, Be = we._eosType, He = ee[ge[0]] & 1 ? R : A;
          if (H.get(q))
            for (var qe = 0; qe < ge.length; qe++) {
              var Oe = ge[qe];
              if (M[Oe] & q) {
                for (var Ze = Ie, et = qe - 1; et >= 0; et--)
                  if (!(M[ge[et]] & l)) {
                    Ze = M[ge[et]];
                    break;
                  }
                $(Oe, Ze & (i | V) ? z : Ze);
              }
            }
          if (H.get(E))
            for (var tt = 0; tt < ge.length; tt++) {
              var vt = ge[tt];
              if (M[vt] & E)
                for (var Je = tt - 1; Je >= -1; Je--) {
                  var ke = Je === -1 ? Ie : M[ge[Je]];
                  if (ke & s) {
                    ke === K && $(vt, L);
                    break;
                  }
                }
            }
          if (H.get(K))
            for (var Bt = 0; Bt < ge.length; Bt++) {
              var Qe = ge[Bt];
              M[Qe] & K && $(Qe, R);
            }
          if (H.get(S) || H.get(B))
            for (var _t = 1; _t < ge.length - 1; _t++) {
              var rn = ge[_t];
              if (M[rn] & (S | B)) {
                for (var ut = 0, on = 0, nt = _t - 1; nt >= 0 && (ut = M[ge[nt]], !!(ut & l)); nt--)
                  ;
                for (var Pt = _t + 1; Pt < ge.length && (on = M[ge[Pt]], !!(on & l)); Pt++)
                  ;
                ut === on && (M[rn] === S ? ut === E : ut & (E | L)) && $(rn, ut);
              }
            }
          if (H.get(E))
            for (var Mt = 0; Mt < ge.length; Mt++) {
              var Ut = ge[Mt];
              if (M[Ut] & E) {
                for (var kt = Mt - 1; kt >= 0 && M[ge[kt]] & (F | l); kt--)
                  $(ge[kt], E);
                for (Mt++; Mt < ge.length && M[ge[Mt]] & (F | l | E); Mt++)
                  M[ge[Mt]] !== E && $(ge[Mt], E);
              }
            }
          if (H.get(F) || H.get(S) || H.get(B))
            for (var Dt = 0; Dt < ge.length; Dt++) {
              var yi = ge[Dt];
              if (M[yi] & (F | S | B)) {
                $(yi, z);
                for (var Zi = Dt - 1; Zi >= 0 && M[ge[Zi]] & l; Zi--)
                  $(ge[Zi], z);
                for (var Ki = Dt + 1; Ki < ge.length && M[ge[Ki]] & l; Ki++)
                  $(ge[Ki], z);
              }
            }
          if (H.get(E))
            for (var qr = 0, rs = Ie; qr < ge.length; qr++) {
              var as = ge[qr], Yr = M[as];
              Yr & E ? rs === A && $(as, A) : Yr & s && (rs = Yr);
            }
          if (H.get(o)) {
            var Mi = R | E | L, ss = Mi | A, Ji = [];
            {
              for (var Wn = [], Xn = 0; Xn < ge.length; Xn++)
                if (M[ge[Xn]] & o) {
                  var Ei = te[ge[Xn]], os = void 0;
                  if (_(Ei) !== null)
                    if (Wn.length < 63)
                      Wn.push({ char: Ei, seqIndex: Xn });
                    else
                      break;
                  else if ((os = D(Ei)) !== null)
                    for (var Ti = Wn.length - 1; Ti >= 0; Ti--) {
                      var jr = Wn[Ti].char;
                      if (jr === os || jr === D(C(Ei)) || _(C(jr)) === Ei) {
                        Ji.push([Wn[Ti].seqIndex, Xn]), Wn.length = Ti;
                        break;
                      }
                    }
                }
              Ji.sort(function(Lt, jt) {
                return Lt[0] - jt[0];
              });
            }
            for (var Zr = 0; Zr < Ji.length; Zr++) {
              for (var ls = Ji[Zr], Qi = ls[0], Kr = ls[1], cs = !1, Yt = 0, Jr = Qi + 1; Jr < Kr; Jr++) {
                var us = ge[Jr];
                if (M[us] & ss) {
                  cs = !0;
                  var hs = M[us] & Mi ? R : A;
                  if (hs === He) {
                    Yt = hs;
                    break;
                  }
                }
              }
              if (cs && !Yt) {
                Yt = Ie;
                for (var Qr = Qi - 1; Qr >= 0; Qr--) {
                  var fs = ge[Qr];
                  if (M[fs] & ss) {
                    var ds = M[fs] & Mi ? R : A;
                    ds !== He ? Yt = ds : Yt = He;
                    break;
                  }
                }
              }
              if (Yt) {
                if (M[ge[Qi]] = M[ge[Kr]] = Yt, Yt !== He) {
                  for (var bi = Qi + 1; bi < ge.length; bi++)
                    if (!(M[ge[bi]] & l)) {
                      h(te[ge[bi]]) & q && (M[ge[bi]] = Yt);
                      break;
                    }
                }
                if (Yt !== He) {
                  for (var Ai = Kr + 1; Ai < ge.length; Ai++)
                    if (!(M[ge[Ai]] & l)) {
                      h(te[ge[Ai]]) & q && (M[ge[Ai]] = Yt);
                      break;
                    }
                }
              }
            }
            for (var gn = 0; gn < ge.length; gn++)
              if (M[ge[gn]] & o) {
                for (var ps = gn, $r = gn, ea = Ie, wi = gn - 1; wi >= 0; wi--)
                  if (M[ge[wi]] & l)
                    ps = wi;
                  else {
                    ea = M[ge[wi]] & Mi ? R : A;
                    break;
                  }
                for (var ms = Be, Ci = gn + 1; Ci < ge.length; Ci++)
                  if (M[ge[Ci]] & (o | l))
                    $r = Ci;
                  else {
                    ms = M[ge[Ci]] & Mi ? R : A;
                    break;
                  }
                for (var ta = ps; ta <= $r; ta++)
                  M[ge[ta]] = ea === ms ? ea : He;
                gn = $r;
              }
          }
        }
        for (var Gt = de.start; Gt <= de.end; Gt++) {
          var Ml = ee[Gt], $i = M[Gt];
          if (Ml & 1 ? $i & (A | E | L) && ee[Gt]++ : $i & R ? ee[Gt]++ : $i & (L | E) && (ee[Gt] += 2), $i & l && (ee[Gt] = Gt === 0 ? de.level : ee[Gt - 1]), Gt === de.end || h(te[Gt]) & (O | k))
            for (var er = Gt; er >= 0 && h(te[er]) & c; er--)
              ee[er] = de.level;
        }
      }
      return {
        levels: ee,
        paragraphs: Se
      };
      function gs(Lt, jt) {
        for (var Ft = Lt; Ft < te.length; Ft++) {
          var vn = M[Ft];
          if (vn & (R | K))
            return 1;
          if (vn & (k | A) || jt && vn === V)
            return 0;
          if (vn & i) {
            var vs = El(Ft);
            Ft = vs === -1 ? te.length : vs;
          }
        }
        return 0;
      }
      function El(Lt) {
        for (var jt = 1, Ft = Lt + 1; Ft < te.length; Ft++) {
          var vn = M[Ft];
          if (vn & k)
            break;
          if (vn & V) {
            if (--jt === 0)
              return Ft;
          } else vn & i && jt++;
        }
        return -1;
      }
    }
    var he = "14>1,j>2,t>2,u>2,1a>g,2v3>1,1>1,1ge>1,1wd>1,b>1,1j>1,f>1,ai>3,-2>3,+1,8>1k0,-1jq>1y7,-1y6>1hf,-1he>1h6,-1h5>1ha,-1h8>1qi,-1pu>1,6>3u,-3s>7,6>1,1>1,f>1,1>1,+2,3>1,1>1,+13,4>1,1>1,6>1eo,-1ee>1,3>1mg,-1me>1mk,-1mj>1mi,-1mg>1mi,-1md>1,1>1,+2,1>10k,-103>1,1>1,4>1,5>1,1>1,+10,3>1,1>8,-7>8,+1,-6>7,+1,a>1,1>1,u>1,u6>1,1>1,+5,26>1,1>1,2>1,2>2,8>1,7>1,4>1,1>1,+5,b8>1,1>1,+3,1>3,-2>1,2>1,1>1,+2,c>1,3>1,1>1,+2,h>1,3>1,a>1,1>1,2>1,3>1,1>1,d>1,f>1,3>1,1a>1,1>1,6>1,7>1,13>1,k>1,1>1,+19,4>1,1>1,+2,2>1,1>1,+18,m>1,a>1,1>1,lk>1,1>1,4>1,2>1,f>1,3>1,1>1,+3,db>1,1>1,+3,3>1,1>1,+2,14qm>1,1>1,+1,6>1,4j>1,j>2,t>2,u>2,2>1,+1", fe;
    function W() {
      if (!fe) {
        var te = v(he, !0), Te = te.map, me = te.reverseMap;
        me.forEach(function(M, y) {
          Te.set(y, M);
        }), fe = Te;
      }
    }
    function ce(te) {
      return W(), fe.get(te) || null;
    }
    function P(te, Te, me, M) {
      var y = te.length;
      me = Math.max(0, me == null ? 0 : +me), M = Math.min(y - 1, M == null ? y - 1 : +M);
      for (var H = /* @__PURE__ */ new Map(), $ = me; $ <= M; $++)
        if (Te[$] & 1) {
          var ee = ce(te[$]);
          ee !== null && H.set($, ee);
        }
      return H;
    }
    function pe(te, Te, me, M) {
      var y = te.length;
      me = Math.max(0, me == null ? 0 : +me), M = Math.min(y - 1, M == null ? y - 1 : +M);
      var H = [];
      return Te.paragraphs.forEach(function($) {
        var ee = Math.max(me, $.start), oe = Math.min(M, $.end);
        if (ee < oe) {
          for (var Se = Te.levels.slice(ee, oe + 1), de = oe; de >= ee && h(te[de]) & c; de--)
            Se[de] = $.level;
          for (var xe = $.level, De = 1 / 0, ye = 0; ye < Se.length; ye++) {
            var Re = Se[ye];
            Re > xe && (xe = Re), Re < De && (De = Re | 1);
          }
          for (var Pe = xe; Pe >= De; Pe--)
            for (var Ue = 0; Ue < Se.length; Ue++)
              if (Se[Ue] >= Pe) {
                for (var Me = Ue; Ue + 1 < Se.length && Se[Ue + 1] >= Pe; )
                  Ue++;
                Ue > Me && H.push([Me + ee, Ue + ee]);
              }
        }
      }), H;
    }
    function ae(te, Te, me, M) {
      var y = ve(te, Te, me, M), H = [].concat(te);
      return y.forEach(function($, ee) {
        H[ee] = (Te.levels[$] & 1 ? ce(te[$]) : null) || te[$];
      }), H.join("");
    }
    function ve(te, Te, me, M) {
      for (var y = pe(te, Te, me, M), H = [], $ = 0; $ < te.length; $++)
        H[$] = $;
      return y.forEach(function(ee) {
        for (var oe = ee[0], Se = ee[1], de = H.slice(oe, Se + 1), xe = de.length; xe--; )
          H[Se - xe] = de[xe];
      }), H;
    }
    return e.closingToOpeningBracket = D, e.getBidiCharType = h, e.getBidiCharTypeName = d, e.getCanonicalBracket = C, e.getEmbeddingLevels = re, e.getMirroredCharacter = ce, e.getMirroredCharactersMap = P, e.getReorderSegments = pe, e.getReorderedIndices = ve, e.getReorderedString = ae, e.openingToClosingBracket = _, Object.defineProperty(e, "__esModule", { value: !0 }), e;
  }({});
  return a;
}
const dl = /\bvoid\s+main\s*\(\s*\)\s*{/g;
function Ya(a) {
  const e = /^[ \t]*#include +<([\w\d./]+)>/gm;
  function t(r, n) {
    let i = Xe[n];
    return i ? Ya(i) : r;
  }
  return a.replace(e, t);
}
const xt = [];
for (let a = 0; a < 256; a++)
  xt[a] = (a < 16 ? "0" : "") + a.toString(16);
function Op() {
  const a = Math.random() * 4294967295 | 0, e = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, r = Math.random() * 4294967295 | 0;
  return (xt[a & 255] + xt[a >> 8 & 255] + xt[a >> 16 & 255] + xt[a >> 24 & 255] + "-" + xt[e & 255] + xt[e >> 8 & 255] + "-" + xt[e >> 16 & 15 | 64] + xt[e >> 24 & 255] + "-" + xt[t & 63 | 128] + xt[t >> 8 & 255] + "-" + xt[t >> 16 & 255] + xt[t >> 24 & 255] + xt[r & 255] + xt[r >> 8 & 255] + xt[r >> 16 & 255] + xt[r >> 24 & 255]).toUpperCase();
}
const Ln = Object.assign || function() {
  let a = arguments[0];
  for (let e = 1, t = arguments.length; e < t; e++) {
    let r = arguments[e];
    if (r)
      for (let n in r)
        Object.prototype.hasOwnProperty.call(r, n) && (a[n] = r[n]);
  }
  return a;
}, Bp = Date.now(), yo = /* @__PURE__ */ new WeakMap(), Mo = /* @__PURE__ */ new Map();
let kp = 1e10;
function ja(a, e) {
  const t = Hp(e);
  let r = yo.get(a);
  if (r || yo.set(a, r = /* @__PURE__ */ Object.create(null)), r[t])
    return new r[t]();
  const n = `_onBeforeCompile${t}`, i = function(c, u) {
    a.onBeforeCompile.call(this, c, u);
    const f = this.customProgramCacheKey() + "|" + c.vertexShader + "|" + c.fragmentShader;
    let h = Mo[f];
    if (!h) {
      const d = Gp(this, c, e, t);
      h = Mo[f] = d;
    }
    c.vertexShader = h.vertexShader, c.fragmentShader = h.fragmentShader, Ln(c.uniforms, this.uniforms), e.timeUniform && (c.uniforms[e.timeUniform] = {
      get value() {
        return Date.now() - Bp;
      }
    }), this[n] && this[n](c);
  }, s = function() {
    return o(e.chained ? a : a.clone());
  }, o = function(c) {
    const u = Object.create(c, l);
    return Object.defineProperty(u, "baseMaterial", { value: a }), Object.defineProperty(u, "id", { value: kp++ }), u.uuid = Op(), u.uniforms = Ln({}, c.uniforms, e.uniforms), u.defines = Ln({}, c.defines, e.defines), u.defines[`TROIKA_DERIVED_MATERIAL_${t}`] = "", u.extensions = Ln({}, c.extensions, e.extensions), u._listeners = void 0, u;
  }, l = {
    constructor: { value: s },
    isDerivedMaterial: { value: !0 },
    type: {
      get: () => a.type,
      set: (c) => {
        a.type = c;
      }
    },
    isDerivedFrom: {
      writable: !0,
      configurable: !0,
      value: function(c) {
        const u = this.baseMaterial;
        return c === u || u.isDerivedMaterial && u.isDerivedFrom(c) || !1;
      }
    },
    customProgramCacheKey: {
      writable: !0,
      configurable: !0,
      value: function() {
        return a.customProgramCacheKey() + "|" + t;
      }
    },
    onBeforeCompile: {
      get() {
        return i;
      },
      set(c) {
        this[n] = c;
      }
    },
    copy: {
      writable: !0,
      configurable: !0,
      value: function(c) {
        return a.copy.call(this, c), !a.isShaderMaterial && !a.isDerivedMaterial && (Ln(this.extensions, c.extensions), Ln(this.defines, c.defines), Ln(this.uniforms, Qa.clone(c.uniforms))), this;
      }
    },
    clone: {
      writable: !0,
      configurable: !0,
      value: function() {
        const c = new a.constructor();
        return o(c).copy(this);
      }
    },
    /**
     * Utility to get a MeshDepthMaterial that will honor this derived material's vertex
     * transformations and discarded fragments.
     */
    getDepthMaterial: {
      writable: !0,
      configurable: !0,
      value: function() {
        let c = this._depthMaterial;
        return c || (c = this._depthMaterial = ja(
          a.isDerivedMaterial ? a.getDepthMaterial() : new $o({ depthPacking: 3201 }),
          e
        ), c.defines.IS_DEPTH_MATERIAL = "", c.uniforms = this.uniforms), c;
      }
    },
    /**
     * Utility to get a MeshDistanceMaterial that will honor this derived material's vertex
     * transformations and discarded fragments.
     */
    getDistanceMaterial: {
      writable: !0,
      configurable: !0,
      value: function() {
        let c = this._distanceMaterial;
        return c || (c = this._distanceMaterial = ja(
          a.isDerivedMaterial ? a.getDistanceMaterial() : new el(),
          e
        ), c.defines.IS_DISTANCE_MATERIAL = "", c.uniforms = this.uniforms), c;
      }
    },
    dispose: {
      writable: !0,
      configurable: !0,
      value() {
        const { _depthMaterial: c, _distanceMaterial: u } = this;
        c && c.dispose(), u && u.dispose(), a.dispose.call(this);
      }
    }
  };
  return r[t] = s, new s();
}
function Gp(a, { vertexShader: e, fragmentShader: t }, r, n) {
  let {
    vertexDefs: i,
    vertexMainIntro: s,
    vertexMainOutro: o,
    vertexTransform: l,
    fragmentDefs: c,
    fragmentMainIntro: u,
    fragmentMainOutro: f,
    fragmentColorTransform: h,
    customRewriter: d,
    timeUniform: g
  } = r;
  if (i = i || "", s = s || "", o = o || "", c = c || "", u = u || "", f = f || "", (l || d) && (e = Ya(e)), (h || d) && (t = t.replace(
    /^[ \t]*#include <((?:tonemapping|encodings|colorspace|fog|premultiplied_alpha|dithering)_fragment)>/gm,
    `
//!BEGIN_POST_CHUNK $1
$&
//!END_POST_CHUNK
`
  ), t = Ya(t)), d) {
    let v = d({ vertexShader: e, fragmentShader: t });
    e = v.vertexShader, t = v.fragmentShader;
  }
  if (h) {
    let v = [];
    t = t.replace(
      /^\/\/!BEGIN_POST_CHUNK[^]+?^\/\/!END_POST_CHUNK/gm,
      // [^]+? = non-greedy match of any chars including newlines
      (m) => (v.push(m), "")
    ), f = `${h}
${v.join(`
`)}
${f}`;
  }
  if (g) {
    const v = `
uniform float ${g};
`;
    i = v + i, c = v + c;
  }
  return l && (e = `vec3 troika_position_${n};
vec3 troika_normal_${n};
vec2 troika_uv_${n};
${e}
`, i = `${i}
void troikaVertexTransform${n}(inout vec3 position, inout vec3 normal, inout vec2 uv) {
  ${l}
}
`, s = `
troika_position_${n} = vec3(position);
troika_normal_${n} = vec3(normal);
troika_uv_${n} = vec2(uv);
troikaVertexTransform${n}(troika_position_${n}, troika_normal_${n}, troika_uv_${n});
${s}
`, e = e.replace(/\b(position|normal|uv)\b/g, (v, m, p, T) => /\battribute\s+vec[23]\s+$/.test(T.substr(0, p)) ? m : `troika_${m}_${n}`), a.map && a.map.channel > 0 || (e = e.replace(/\bMAP_UV\b/g, `troika_uv_${n}`))), e = Eo(e, n, i, s, o), t = Eo(t, n, c, u, f), {
    vertexShader: e,
    fragmentShader: t
  };
}
function Eo(a, e, t, r, n) {
  return (r || n || t) && (a = a.replace(
    dl,
    `
${t}
void troikaOrigMain${e}() {`
  ), a += `
void main() {
  ${r}
  troikaOrigMain${e}();
  ${n}
}`), a;
}
function zp(a, e) {
  return a === "uniforms" ? void 0 : typeof e == "function" ? e.toString() : e;
}
let Vp = 0;
const To = /* @__PURE__ */ new Map();
function Hp(a) {
  const e = JSON.stringify(a, zp);
  let t = To.get(e);
  return t == null && To.set(e, t = ++Vp), t;
}
/*!
Custom build of Typr.ts (https://github.com/fredli74/Typr.ts) for use in Troika text rendering.
Original MIT license applies: https://github.com/fredli74/Typr.ts/blob/master/LICENSE
*/
function Wp() {
  return typeof window > "u" && (self.window = self), function(a) {
    var e = { parse: function(n) {
      var i = e._bin, s = new Uint8Array(n);
      if (i.readASCII(s, 0, 4) == "ttcf") {
        var o = 4;
        i.readUshort(s, o), o += 2, i.readUshort(s, o), o += 2;
        var l = i.readUint(s, o);
        o += 4;
        for (var c = [], u = 0; u < l; u++) {
          var f = i.readUint(s, o);
          o += 4, c.push(e._readFont(s, f));
        }
        return c;
      }
      return [e._readFont(s, 0)];
    }, _readFont: function(n, i) {
      var s = e._bin, o = i;
      s.readFixed(n, i), i += 4;
      var l = s.readUshort(n, i);
      i += 2, s.readUshort(n, i), i += 2, s.readUshort(n, i), i += 2, s.readUshort(n, i), i += 2;
      for (var c = ["cmap", "head", "hhea", "maxp", "hmtx", "name", "OS/2", "post", "loca", "glyf", "kern", "CFF ", "GDEF", "GPOS", "GSUB", "SVG "], u = { _data: n, _offset: o }, f = {}, h = 0; h < l; h++) {
        var d = s.readASCII(n, i, 4);
        i += 4, s.readUint(n, i), i += 4;
        var g = s.readUint(n, i);
        i += 4;
        var v = s.readUint(n, i);
        i += 4, f[d] = { offset: g, length: v };
      }
      for (h = 0; h < c.length; h++) {
        var m = c[h];
        f[m] && (u[m.trim()] = e[m.trim()].parse(n, f[m].offset, f[m].length, u));
      }
      return u;
    }, _tabOffset: function(n, i, s) {
      for (var o = e._bin, l = o.readUshort(n, s + 4), c = s + 12, u = 0; u < l; u++) {
        var f = o.readASCII(n, c, 4);
        c += 4, o.readUint(n, c), c += 4;
        var h = o.readUint(n, c);
        if (c += 4, o.readUint(n, c), c += 4, f == i) return h;
      }
      return 0;
    } };
    e._bin = { readFixed: function(n, i) {
      return (n[i] << 8 | n[i + 1]) + (n[i + 2] << 8 | n[i + 3]) / 65540;
    }, readF2dot14: function(n, i) {
      return e._bin.readShort(n, i) / 16384;
    }, readInt: function(n, i) {
      return e._bin._view(n).getInt32(i);
    }, readInt8: function(n, i) {
      return e._bin._view(n).getInt8(i);
    }, readShort: function(n, i) {
      return e._bin._view(n).getInt16(i);
    }, readUshort: function(n, i) {
      return e._bin._view(n).getUint16(i);
    }, readUshorts: function(n, i, s) {
      for (var o = [], l = 0; l < s; l++) o.push(e._bin.readUshort(n, i + 2 * l));
      return o;
    }, readUint: function(n, i) {
      return e._bin._view(n).getUint32(i);
    }, readUint64: function(n, i) {
      return 4294967296 * e._bin.readUint(n, i) + e._bin.readUint(n, i + 4);
    }, readASCII: function(n, i, s) {
      for (var o = "", l = 0; l < s; l++) o += String.fromCharCode(n[i + l]);
      return o;
    }, readUnicode: function(n, i, s) {
      for (var o = "", l = 0; l < s; l++) {
        var c = n[i++] << 8 | n[i++];
        o += String.fromCharCode(c);
      }
      return o;
    }, _tdec: typeof window < "u" && window.TextDecoder ? new window.TextDecoder() : null, readUTF8: function(n, i, s) {
      var o = e._bin._tdec;
      return o && i == 0 && s == n.length ? o.decode(n) : e._bin.readASCII(n, i, s);
    }, readBytes: function(n, i, s) {
      for (var o = [], l = 0; l < s; l++) o.push(n[i + l]);
      return o;
    }, readASCIIArray: function(n, i, s) {
      for (var o = [], l = 0; l < s; l++) o.push(String.fromCharCode(n[i + l]));
      return o;
    }, _view: function(n) {
      return n._dataView || (n._dataView = n.buffer ? new DataView(n.buffer, n.byteOffset, n.byteLength) : new DataView(new Uint8Array(n).buffer));
    } }, e._lctf = {}, e._lctf.parse = function(n, i, s, o, l) {
      var c = e._bin, u = {}, f = i;
      c.readFixed(n, i), i += 4;
      var h = c.readUshort(n, i);
      i += 2;
      var d = c.readUshort(n, i);
      i += 2;
      var g = c.readUshort(n, i);
      return i += 2, u.scriptList = e._lctf.readScriptList(n, f + h), u.featureList = e._lctf.readFeatureList(n, f + d), u.lookupList = e._lctf.readLookupList(n, f + g, l), u;
    }, e._lctf.readLookupList = function(n, i, s) {
      var o = e._bin, l = i, c = [], u = o.readUshort(n, i);
      i += 2;
      for (var f = 0; f < u; f++) {
        var h = o.readUshort(n, i);
        i += 2;
        var d = e._lctf.readLookupTable(n, l + h, s);
        c.push(d);
      }
      return c;
    }, e._lctf.readLookupTable = function(n, i, s) {
      var o = e._bin, l = i, c = { tabs: [] };
      c.ltype = o.readUshort(n, i), i += 2, c.flag = o.readUshort(n, i), i += 2;
      var u = o.readUshort(n, i);
      i += 2;
      for (var f = c.ltype, h = 0; h < u; h++) {
        var d = o.readUshort(n, i);
        i += 2;
        var g = s(n, f, l + d, c);
        c.tabs.push(g);
      }
      return c;
    }, e._lctf.numOfOnes = function(n) {
      for (var i = 0, s = 0; s < 32; s++) n >>> s & 1 && i++;
      return i;
    }, e._lctf.readClassDef = function(n, i) {
      var s = e._bin, o = [], l = s.readUshort(n, i);
      if (i += 2, l == 1) {
        var c = s.readUshort(n, i);
        i += 2;
        var u = s.readUshort(n, i);
        i += 2;
        for (var f = 0; f < u; f++) o.push(c + f), o.push(c + f), o.push(s.readUshort(n, i)), i += 2;
      }
      if (l == 2) {
        var h = s.readUshort(n, i);
        for (i += 2, f = 0; f < h; f++) o.push(s.readUshort(n, i)), i += 2, o.push(s.readUshort(n, i)), i += 2, o.push(s.readUshort(n, i)), i += 2;
      }
      return o;
    }, e._lctf.getInterval = function(n, i) {
      for (var s = 0; s < n.length; s += 3) {
        var o = n[s], l = n[s + 1];
        if (n[s + 2], o <= i && i <= l) return s;
      }
      return -1;
    }, e._lctf.readCoverage = function(n, i) {
      var s = e._bin, o = {};
      o.fmt = s.readUshort(n, i), i += 2;
      var l = s.readUshort(n, i);
      return i += 2, o.fmt == 1 && (o.tab = s.readUshorts(n, i, l)), o.fmt == 2 && (o.tab = s.readUshorts(n, i, 3 * l)), o;
    }, e._lctf.coverageIndex = function(n, i) {
      var s = n.tab;
      if (n.fmt == 1) return s.indexOf(i);
      if (n.fmt == 2) {
        var o = e._lctf.getInterval(s, i);
        if (o != -1) return s[o + 2] + (i - s[o]);
      }
      return -1;
    }, e._lctf.readFeatureList = function(n, i) {
      var s = e._bin, o = i, l = [], c = s.readUshort(n, i);
      i += 2;
      for (var u = 0; u < c; u++) {
        var f = s.readASCII(n, i, 4);
        i += 4;
        var h = s.readUshort(n, i);
        i += 2;
        var d = e._lctf.readFeatureTable(n, o + h);
        d.tag = f.trim(), l.push(d);
      }
      return l;
    }, e._lctf.readFeatureTable = function(n, i) {
      var s = e._bin, o = i, l = {}, c = s.readUshort(n, i);
      i += 2, c > 0 && (l.featureParams = o + c);
      var u = s.readUshort(n, i);
      i += 2, l.tab = [];
      for (var f = 0; f < u; f++) l.tab.push(s.readUshort(n, i + 2 * f));
      return l;
    }, e._lctf.readScriptList = function(n, i) {
      var s = e._bin, o = i, l = {}, c = s.readUshort(n, i);
      i += 2;
      for (var u = 0; u < c; u++) {
        var f = s.readASCII(n, i, 4);
        i += 4;
        var h = s.readUshort(n, i);
        i += 2, l[f.trim()] = e._lctf.readScriptTable(n, o + h);
      }
      return l;
    }, e._lctf.readScriptTable = function(n, i) {
      var s = e._bin, o = i, l = {}, c = s.readUshort(n, i);
      i += 2, c > 0 && (l.default = e._lctf.readLangSysTable(n, o + c));
      var u = s.readUshort(n, i);
      i += 2;
      for (var f = 0; f < u; f++) {
        var h = s.readASCII(n, i, 4);
        i += 4;
        var d = s.readUshort(n, i);
        i += 2, l[h.trim()] = e._lctf.readLangSysTable(n, o + d);
      }
      return l;
    }, e._lctf.readLangSysTable = function(n, i) {
      var s = e._bin, o = {};
      s.readUshort(n, i), i += 2, o.reqFeature = s.readUshort(n, i), i += 2;
      var l = s.readUshort(n, i);
      return i += 2, o.features = s.readUshorts(n, i, l), o;
    }, e.CFF = {}, e.CFF.parse = function(n, i, s) {
      var o = e._bin;
      (n = new Uint8Array(n.buffer, i, s))[i = 0], n[++i], n[++i], n[++i], i++;
      var l = [];
      i = e.CFF.readIndex(n, i, l);
      for (var c = [], u = 0; u < l.length - 1; u++) c.push(o.readASCII(n, i + l[u], l[u + 1] - l[u]));
      i += l[l.length - 1];
      var f = [];
      i = e.CFF.readIndex(n, i, f);
      var h = [];
      for (u = 0; u < f.length - 1; u++) h.push(e.CFF.readDict(n, i + f[u], i + f[u + 1]));
      i += f[f.length - 1];
      var d = h[0], g = [];
      i = e.CFF.readIndex(n, i, g);
      var v = [];
      for (u = 0; u < g.length - 1; u++) v.push(o.readASCII(n, i + g[u], g[u + 1] - g[u]));
      if (i += g[g.length - 1], e.CFF.readSubrs(n, i, d), d.CharStrings) {
        i = d.CharStrings, g = [], i = e.CFF.readIndex(n, i, g);
        var m = [];
        for (u = 0; u < g.length - 1; u++) m.push(o.readBytes(n, i + g[u], g[u + 1] - g[u]));
        d.CharStrings = m;
      }
      if (d.ROS) {
        i = d.FDArray;
        var p = [];
        for (i = e.CFF.readIndex(n, i, p), d.FDArray = [], u = 0; u < p.length - 1; u++) {
          var T = e.CFF.readDict(n, i + p[u], i + p[u + 1]);
          e.CFF._readFDict(n, T, v), d.FDArray.push(T);
        }
        i += p[p.length - 1], i = d.FDSelect, d.FDSelect = [];
        var x = n[i];
        if (i++, x != 3) throw x;
        var _ = o.readUshort(n, i);
        for (i += 2, u = 0; u < _ + 1; u++) d.FDSelect.push(o.readUshort(n, i), n[i + 2]), i += 3;
      }
      return d.Encoding && (d.Encoding = e.CFF.readEncoding(n, d.Encoding, d.CharStrings.length)), d.charset && (d.charset = e.CFF.readCharset(n, d.charset, d.CharStrings.length)), e.CFF._readFDict(n, d, v), d;
    }, e.CFF._readFDict = function(n, i, s) {
      var o;
      for (var l in i.Private && (o = i.Private[1], i.Private = e.CFF.readDict(n, o, o + i.Private[0]), i.Private.Subrs && e.CFF.readSubrs(n, o + i.Private.Subrs, i.Private)), i) ["FamilyName", "FontName", "FullName", "Notice", "version", "Copyright"].indexOf(l) != -1 && (i[l] = s[i[l] - 426 + 35]);
    }, e.CFF.readSubrs = function(n, i, s) {
      var o = e._bin, l = [];
      i = e.CFF.readIndex(n, i, l);
      var c, u = l.length;
      c = u < 1240 ? 107 : u < 33900 ? 1131 : 32768, s.Bias = c, s.Subrs = [];
      for (var f = 0; f < l.length - 1; f++) s.Subrs.push(o.readBytes(n, i + l[f], l[f + 1] - l[f]));
    }, e.CFF.tableSE = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 0, 111, 112, 113, 114, 0, 115, 116, 117, 118, 119, 120, 121, 122, 0, 123, 0, 124, 125, 126, 127, 128, 129, 130, 131, 0, 132, 133, 0, 134, 135, 136, 137, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 138, 0, 139, 0, 0, 0, 0, 140, 141, 142, 143, 0, 0, 0, 0, 0, 144, 0, 0, 0, 145, 0, 0, 146, 147, 148, 149, 0, 0, 0, 0], e.CFF.glyphByUnicode = function(n, i) {
      for (var s = 0; s < n.charset.length; s++) if (n.charset[s] == i) return s;
      return -1;
    }, e.CFF.glyphBySE = function(n, i) {
      return i < 0 || i > 255 ? -1 : e.CFF.glyphByUnicode(n, e.CFF.tableSE[i]);
    }, e.CFF.readEncoding = function(n, i, s) {
      e._bin;
      var o = [".notdef"], l = n[i];
      if (i++, l != 0) throw "error: unknown encoding format: " + l;
      var c = n[i];
      i++;
      for (var u = 0; u < c; u++) o.push(n[i + u]);
      return o;
    }, e.CFF.readCharset = function(n, i, s) {
      var o = e._bin, l = [".notdef"], c = n[i];
      if (i++, c == 0) for (var u = 0; u < s; u++) {
        var f = o.readUshort(n, i);
        i += 2, l.push(f);
      }
      else {
        if (c != 1 && c != 2) throw "error: format: " + c;
        for (; l.length < s; ) {
          f = o.readUshort(n, i), i += 2;
          var h = 0;
          for (c == 1 ? (h = n[i], i++) : (h = o.readUshort(n, i), i += 2), u = 0; u <= h; u++) l.push(f), f++;
        }
      }
      return l;
    }, e.CFF.readIndex = function(n, i, s) {
      var o = e._bin, l = o.readUshort(n, i) + 1, c = n[i += 2];
      if (i++, c == 1) for (var u = 0; u < l; u++) s.push(n[i + u]);
      else if (c == 2) for (u = 0; u < l; u++) s.push(o.readUshort(n, i + 2 * u));
      else if (c == 3) for (u = 0; u < l; u++) s.push(16777215 & o.readUint(n, i + 3 * u - 1));
      else if (l != 1) throw "unsupported offset size: " + c + ", count: " + l;
      return (i += l * c) - 1;
    }, e.CFF.getCharString = function(n, i, s) {
      var o = e._bin, l = n[i], c = n[i + 1];
      n[i + 2], n[i + 3], n[i + 4];
      var u = 1, f = null, h = null;
      l <= 20 && (f = l, u = 1), l == 12 && (f = 100 * l + c, u = 2), 21 <= l && l <= 27 && (f = l, u = 1), l == 28 && (h = o.readShort(n, i + 1), u = 3), 29 <= l && l <= 31 && (f = l, u = 1), 32 <= l && l <= 246 && (h = l - 139, u = 1), 247 <= l && l <= 250 && (h = 256 * (l - 247) + c + 108, u = 2), 251 <= l && l <= 254 && (h = 256 * -(l - 251) - c - 108, u = 2), l == 255 && (h = o.readInt(n, i + 1) / 65535, u = 5), s.val = h ?? "o" + f, s.size = u;
    }, e.CFF.readCharString = function(n, i, s) {
      for (var o = i + s, l = e._bin, c = []; i < o; ) {
        var u = n[i], f = n[i + 1];
        n[i + 2], n[i + 3], n[i + 4];
        var h = 1, d = null, g = null;
        u <= 20 && (d = u, h = 1), u == 12 && (d = 100 * u + f, h = 2), u != 19 && u != 20 || (d = u, h = 2), 21 <= u && u <= 27 && (d = u, h = 1), u == 28 && (g = l.readShort(n, i + 1), h = 3), 29 <= u && u <= 31 && (d = u, h = 1), 32 <= u && u <= 246 && (g = u - 139, h = 1), 247 <= u && u <= 250 && (g = 256 * (u - 247) + f + 108, h = 2), 251 <= u && u <= 254 && (g = 256 * -(u - 251) - f - 108, h = 2), u == 255 && (g = l.readInt(n, i + 1) / 65535, h = 5), c.push(g ?? "o" + d), i += h;
      }
      return c;
    }, e.CFF.readDict = function(n, i, s) {
      for (var o = e._bin, l = {}, c = []; i < s; ) {
        var u = n[i], f = n[i + 1];
        n[i + 2], n[i + 3], n[i + 4];
        var h = 1, d = null, g = null;
        if (u == 28 && (g = o.readShort(n, i + 1), h = 3), u == 29 && (g = o.readInt(n, i + 1), h = 5), 32 <= u && u <= 246 && (g = u - 139, h = 1), 247 <= u && u <= 250 && (g = 256 * (u - 247) + f + 108, h = 2), 251 <= u && u <= 254 && (g = 256 * -(u - 251) - f - 108, h = 2), u == 255) throw g = o.readInt(n, i + 1) / 65535, h = 5, "unknown number";
        if (u == 30) {
          var v = [];
          for (h = 1; ; ) {
            var m = n[i + h];
            h++;
            var p = m >> 4, T = 15 & m;
            if (p != 15 && v.push(p), T != 15 && v.push(T), T == 15) break;
          }
          for (var x = "", _ = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ".", "e", "e-", "reserved", "-", "endOfNumber"], D = 0; D < v.length; D++) x += _[v[D]];
          g = parseFloat(x);
        }
        u <= 21 && (d = ["version", "Notice", "FullName", "FamilyName", "Weight", "FontBBox", "BlueValues", "OtherBlues", "FamilyBlues", "FamilyOtherBlues", "StdHW", "StdVW", "escape", "UniqueID", "XUID", "charset", "Encoding", "CharStrings", "Private", "Subrs", "defaultWidthX", "nominalWidthX"][u], h = 1, u == 12 && (d = ["Copyright", "isFixedPitch", "ItalicAngle", "UnderlinePosition", "UnderlineThickness", "PaintType", "CharstringType", "FontMatrix", "StrokeWidth", "BlueScale", "BlueShift", "BlueFuzz", "StemSnapH", "StemSnapV", "ForceBold", 0, 0, "LanguageGroup", "ExpansionFactor", "initialRandomSeed", "SyntheticBase", "PostScript", "BaseFontName", "BaseFontBlend", 0, 0, 0, 0, 0, 0, "ROS", "CIDFontVersion", "CIDFontRevision", "CIDFontType", "CIDCount", "UIDBase", "FDArray", "FDSelect", "FontName"][f], h = 2)), d != null ? (l[d] = c.length == 1 ? c[0] : c, c = []) : c.push(g), i += h;
      }
      return l;
    }, e.cmap = {}, e.cmap.parse = function(n, i, s) {
      n = new Uint8Array(n.buffer, i, s), i = 0;
      var o = e._bin, l = {};
      o.readUshort(n, i), i += 2;
      var c = o.readUshort(n, i);
      i += 2;
      var u = [];
      l.tables = [];
      for (var f = 0; f < c; f++) {
        var h = o.readUshort(n, i);
        i += 2;
        var d = o.readUshort(n, i);
        i += 2;
        var g = o.readUint(n, i);
        i += 4;
        var v = "p" + h + "e" + d, m = u.indexOf(g);
        if (m == -1) {
          var p;
          m = l.tables.length, u.push(g);
          var T = o.readUshort(n, g);
          T == 0 ? p = e.cmap.parse0(n, g) : T == 4 ? p = e.cmap.parse4(n, g) : T == 6 ? p = e.cmap.parse6(n, g) : T == 12 ? p = e.cmap.parse12(n, g) : console.debug("unknown format: " + T, h, d, g), l.tables.push(p);
        }
        if (l[v] != null) throw "multiple tables for one platform+encoding";
        l[v] = m;
      }
      return l;
    }, e.cmap.parse0 = function(n, i) {
      var s = e._bin, o = {};
      o.format = s.readUshort(n, i), i += 2;
      var l = s.readUshort(n, i);
      i += 2, s.readUshort(n, i), i += 2, o.map = [];
      for (var c = 0; c < l - 6; c++) o.map.push(n[i + c]);
      return o;
    }, e.cmap.parse4 = function(n, i) {
      var s = e._bin, o = i, l = {};
      l.format = s.readUshort(n, i), i += 2;
      var c = s.readUshort(n, i);
      i += 2, s.readUshort(n, i), i += 2;
      var u = s.readUshort(n, i);
      i += 2;
      var f = u / 2;
      l.searchRange = s.readUshort(n, i), i += 2, l.entrySelector = s.readUshort(n, i), i += 2, l.rangeShift = s.readUshort(n, i), i += 2, l.endCount = s.readUshorts(n, i, f), i += 2 * f, i += 2, l.startCount = s.readUshorts(n, i, f), i += 2 * f, l.idDelta = [];
      for (var h = 0; h < f; h++) l.idDelta.push(s.readShort(n, i)), i += 2;
      for (l.idRangeOffset = s.readUshorts(n, i, f), i += 2 * f, l.glyphIdArray = []; i < o + c; ) l.glyphIdArray.push(s.readUshort(n, i)), i += 2;
      return l;
    }, e.cmap.parse6 = function(n, i) {
      var s = e._bin, o = {};
      o.format = s.readUshort(n, i), i += 2, s.readUshort(n, i), i += 2, s.readUshort(n, i), i += 2, o.firstCode = s.readUshort(n, i), i += 2;
      var l = s.readUshort(n, i);
      i += 2, o.glyphIdArray = [];
      for (var c = 0; c < l; c++) o.glyphIdArray.push(s.readUshort(n, i)), i += 2;
      return o;
    }, e.cmap.parse12 = function(n, i) {
      var s = e._bin, o = {};
      o.format = s.readUshort(n, i), i += 2, i += 2, s.readUint(n, i), i += 4, s.readUint(n, i), i += 4;
      var l = s.readUint(n, i);
      i += 4, o.groups = [];
      for (var c = 0; c < l; c++) {
        var u = i + 12 * c, f = s.readUint(n, u + 0), h = s.readUint(n, u + 4), d = s.readUint(n, u + 8);
        o.groups.push([f, h, d]);
      }
      return o;
    }, e.glyf = {}, e.glyf.parse = function(n, i, s, o) {
      for (var l = [], c = 0; c < o.maxp.numGlyphs; c++) l.push(null);
      return l;
    }, e.glyf._parseGlyf = function(n, i) {
      var s = e._bin, o = n._data, l = e._tabOffset(o, "glyf", n._offset) + n.loca[i];
      if (n.loca[i] == n.loca[i + 1]) return null;
      var c = {};
      if (c.noc = s.readShort(o, l), l += 2, c.xMin = s.readShort(o, l), l += 2, c.yMin = s.readShort(o, l), l += 2, c.xMax = s.readShort(o, l), l += 2, c.yMax = s.readShort(o, l), l += 2, c.xMin >= c.xMax || c.yMin >= c.yMax) return null;
      if (c.noc > 0) {
        c.endPts = [];
        for (var u = 0; u < c.noc; u++) c.endPts.push(s.readUshort(o, l)), l += 2;
        var f = s.readUshort(o, l);
        if (l += 2, o.length - l < f) return null;
        c.instructions = s.readBytes(o, l, f), l += f;
        var h = c.endPts[c.noc - 1] + 1;
        for (c.flags = [], u = 0; u < h; u++) {
          var d = o[l];
          if (l++, c.flags.push(d), (8 & d) != 0) {
            var g = o[l];
            l++;
            for (var v = 0; v < g; v++) c.flags.push(d), u++;
          }
        }
        for (c.xs = [], u = 0; u < h; u++) {
          var m = (2 & c.flags[u]) != 0, p = (16 & c.flags[u]) != 0;
          m ? (c.xs.push(p ? o[l] : -o[l]), l++) : p ? c.xs.push(0) : (c.xs.push(s.readShort(o, l)), l += 2);
        }
        for (c.ys = [], u = 0; u < h; u++)
          m = (4 & c.flags[u]) != 0, p = (32 & c.flags[u]) != 0, m ? (c.ys.push(p ? o[l] : -o[l]), l++) : p ? c.ys.push(0) : (c.ys.push(s.readShort(o, l)), l += 2);
        var T = 0, x = 0;
        for (u = 0; u < h; u++) T += c.xs[u], x += c.ys[u], c.xs[u] = T, c.ys[u] = x;
      } else {
        var _;
        c.parts = [];
        do {
          _ = s.readUshort(o, l), l += 2;
          var D = { m: { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 }, p1: -1, p2: -1 };
          if (c.parts.push(D), D.glyphIndex = s.readUshort(o, l), l += 2, 1 & _) {
            var C = s.readShort(o, l);
            l += 2;
            var A = s.readShort(o, l);
            l += 2;
          } else
            C = s.readInt8(o, l), l++, A = s.readInt8(o, l), l++;
          2 & _ ? (D.m.tx = C, D.m.ty = A) : (D.p1 = C, D.p2 = A), 8 & _ ? (D.m.a = D.m.d = s.readF2dot14(o, l), l += 2) : 64 & _ ? (D.m.a = s.readF2dot14(o, l), l += 2, D.m.d = s.readF2dot14(o, l), l += 2) : 128 & _ && (D.m.a = s.readF2dot14(o, l), l += 2, D.m.b = s.readF2dot14(o, l), l += 2, D.m.c = s.readF2dot14(o, l), l += 2, D.m.d = s.readF2dot14(o, l), l += 2);
        } while (32 & _);
        if (256 & _) {
          var R = s.readUshort(o, l);
          for (l += 2, c.instr = [], u = 0; u < R; u++) c.instr.push(o[l]), l++;
        }
      }
      return c;
    }, e.GDEF = {}, e.GDEF.parse = function(n, i, s, o) {
      var l = i;
      i += 4;
      var c = e._bin.readUshort(n, i);
      return { glyphClassDef: c === 0 ? null : e._lctf.readClassDef(n, l + c) };
    }, e.GPOS = {}, e.GPOS.parse = function(n, i, s, o) {
      return e._lctf.parse(n, i, s, o, e.GPOS.subt);
    }, e.GPOS.subt = function(n, i, s, o) {
      var l = e._bin, c = s, u = {};
      if (u.fmt = l.readUshort(n, s), s += 2, i == 1 || i == 2 || i == 3 || i == 7 || i == 8 && u.fmt <= 2) {
        var f = l.readUshort(n, s);
        s += 2, u.coverage = e._lctf.readCoverage(n, f + c);
      }
      if (i == 1 && u.fmt == 1) {
        var h = l.readUshort(n, s);
        s += 2, h != 0 && (u.pos = e.GPOS.readValueRecord(n, s, h));
      } else if (i == 2 && u.fmt >= 1 && u.fmt <= 2) {
        h = l.readUshort(n, s), s += 2;
        var d = l.readUshort(n, s);
        s += 2;
        var g = e._lctf.numOfOnes(h), v = e._lctf.numOfOnes(d);
        if (u.fmt == 1) {
          u.pairsets = [];
          var m = l.readUshort(n, s);
          s += 2;
          for (var p = 0; p < m; p++) {
            var T = c + l.readUshort(n, s);
            s += 2;
            var x = l.readUshort(n, T);
            T += 2;
            for (var _ = [], D = 0; D < x; D++) {
              var C = l.readUshort(n, T);
              T += 2, h != 0 && (L = e.GPOS.readValueRecord(n, T, h), T += 2 * g), d != 0 && (B = e.GPOS.readValueRecord(n, T, d), T += 2 * v), _.push({ gid2: C, val1: L, val2: B });
            }
            u.pairsets.push(_);
          }
        }
        if (u.fmt == 2) {
          var A = l.readUshort(n, s);
          s += 2;
          var R = l.readUshort(n, s);
          s += 2;
          var E = l.readUshort(n, s);
          s += 2;
          var S = l.readUshort(n, s);
          for (s += 2, u.classDef1 = e._lctf.readClassDef(n, c + A), u.classDef2 = e._lctf.readClassDef(n, c + R), u.matrix = [], p = 0; p < E; p++) {
            var F = [];
            for (D = 0; D < S; D++) {
              var L = null, B = null;
              h != 0 && (L = e.GPOS.readValueRecord(n, s, h), s += 2 * g), d != 0 && (B = e.GPOS.readValueRecord(n, s, d), s += 2 * v), F.push({ val1: L, val2: B });
            }
            u.matrix.push(F);
          }
        }
      } else if (i == 4 && u.fmt == 1) u.markCoverage = e._lctf.readCoverage(n, l.readUshort(n, s) + c), u.baseCoverage = e._lctf.readCoverage(n, l.readUshort(n, s + 2) + c), u.markClassCount = l.readUshort(n, s + 4), u.markArray = e.GPOS.readMarkArray(n, l.readUshort(n, s + 6) + c), u.baseArray = e.GPOS.readBaseArray(n, l.readUshort(n, s + 8) + c, u.markClassCount);
      else if (i == 6 && u.fmt == 1) u.mark1Coverage = e._lctf.readCoverage(n, l.readUshort(n, s) + c), u.mark2Coverage = e._lctf.readCoverage(n, l.readUshort(n, s + 2) + c), u.markClassCount = l.readUshort(n, s + 4), u.mark1Array = e.GPOS.readMarkArray(n, l.readUshort(n, s + 6) + c), u.mark2Array = e.GPOS.readBaseArray(n, l.readUshort(n, s + 8) + c, u.markClassCount);
      else {
        if (i == 9 && u.fmt == 1) {
          var k = l.readUshort(n, s);
          s += 2;
          var O = l.readUint(n, s);
          if (s += 4, o.ltype == 9) o.ltype = k;
          else if (o.ltype != k) throw "invalid extension substitution";
          return e.GPOS.subt(n, o.ltype, c + O);
        }
        console.debug("unsupported GPOS table LookupType", i, "format", u.fmt);
      }
      return u;
    }, e.GPOS.readValueRecord = function(n, i, s) {
      var o = e._bin, l = [];
      return l.push(1 & s ? o.readShort(n, i) : 0), i += 1 & s ? 2 : 0, l.push(2 & s ? o.readShort(n, i) : 0), i += 2 & s ? 2 : 0, l.push(4 & s ? o.readShort(n, i) : 0), i += 4 & s ? 2 : 0, l.push(8 & s ? o.readShort(n, i) : 0), i += 8 & s ? 2 : 0, l;
    }, e.GPOS.readBaseArray = function(n, i, s) {
      var o = e._bin, l = [], c = i, u = o.readUshort(n, i);
      i += 2;
      for (var f = 0; f < u; f++) {
        for (var h = [], d = 0; d < s; d++) h.push(e.GPOS.readAnchorRecord(n, c + o.readUshort(n, i))), i += 2;
        l.push(h);
      }
      return l;
    }, e.GPOS.readMarkArray = function(n, i) {
      var s = e._bin, o = [], l = i, c = s.readUshort(n, i);
      i += 2;
      for (var u = 0; u < c; u++) {
        var f = e.GPOS.readAnchorRecord(n, s.readUshort(n, i + 2) + l);
        f.markClass = s.readUshort(n, i), o.push(f), i += 4;
      }
      return o;
    }, e.GPOS.readAnchorRecord = function(n, i) {
      var s = e._bin, o = {};
      return o.fmt = s.readUshort(n, i), o.x = s.readShort(n, i + 2), o.y = s.readShort(n, i + 4), o;
    }, e.GSUB = {}, e.GSUB.parse = function(n, i, s, o) {
      return e._lctf.parse(n, i, s, o, e.GSUB.subt);
    }, e.GSUB.subt = function(n, i, s, o) {
      var l = e._bin, c = s, u = {};
      if (u.fmt = l.readUshort(n, s), s += 2, i != 1 && i != 2 && i != 4 && i != 5 && i != 6) return null;
      if (i == 1 || i == 2 || i == 4 || i == 5 && u.fmt <= 2 || i == 6 && u.fmt <= 2) {
        var f = l.readUshort(n, s);
        s += 2, u.coverage = e._lctf.readCoverage(n, c + f);
      }
      if (i == 1 && u.fmt >= 1 && u.fmt <= 2) {
        if (u.fmt == 1) u.delta = l.readShort(n, s), s += 2;
        else if (u.fmt == 2) {
          var h = l.readUshort(n, s);
          s += 2, u.newg = l.readUshorts(n, s, h), s += 2 * u.newg.length;
        }
      } else if (i == 2 && u.fmt == 1) {
        h = l.readUshort(n, s), s += 2, u.seqs = [];
        for (var d = 0; d < h; d++) {
          var g = l.readUshort(n, s) + c;
          s += 2;
          var v = l.readUshort(n, g);
          u.seqs.push(l.readUshorts(n, g + 2, v));
        }
      } else if (i == 4)
        for (u.vals = [], h = l.readUshort(n, s), s += 2, d = 0; d < h; d++) {
          var m = l.readUshort(n, s);
          s += 2, u.vals.push(e.GSUB.readLigatureSet(n, c + m));
        }
      else if (i == 5 && u.fmt == 2) {
        if (u.fmt == 2) {
          var p = l.readUshort(n, s);
          s += 2, u.cDef = e._lctf.readClassDef(n, c + p), u.scset = [];
          var T = l.readUshort(n, s);
          for (s += 2, d = 0; d < T; d++) {
            var x = l.readUshort(n, s);
            s += 2, u.scset.push(x == 0 ? null : e.GSUB.readSubClassSet(n, c + x));
          }
        }
      } else if (i == 6 && u.fmt == 3) {
        if (u.fmt == 3) {
          for (d = 0; d < 3; d++) {
            h = l.readUshort(n, s), s += 2;
            for (var _ = [], D = 0; D < h; D++) _.push(e._lctf.readCoverage(n, c + l.readUshort(n, s + 2 * D)));
            s += 2 * h, d == 0 && (u.backCvg = _), d == 1 && (u.inptCvg = _), d == 2 && (u.ahedCvg = _);
          }
          h = l.readUshort(n, s), s += 2, u.lookupRec = e.GSUB.readSubstLookupRecords(n, s, h);
        }
      } else {
        if (i == 7 && u.fmt == 1) {
          var C = l.readUshort(n, s);
          s += 2;
          var A = l.readUint(n, s);
          if (s += 4, o.ltype == 9) o.ltype = C;
          else if (o.ltype != C) throw "invalid extension substitution";
          return e.GSUB.subt(n, o.ltype, c + A);
        }
        console.debug("unsupported GSUB table LookupType", i, "format", u.fmt);
      }
      return u;
    }, e.GSUB.readSubClassSet = function(n, i) {
      var s = e._bin.readUshort, o = i, l = [], c = s(n, i);
      i += 2;
      for (var u = 0; u < c; u++) {
        var f = s(n, i);
        i += 2, l.push(e.GSUB.readSubClassRule(n, o + f));
      }
      return l;
    }, e.GSUB.readSubClassRule = function(n, i) {
      var s = e._bin.readUshort, o = {}, l = s(n, i), c = s(n, i += 2);
      i += 2, o.input = [];
      for (var u = 0; u < l - 1; u++) o.input.push(s(n, i)), i += 2;
      return o.substLookupRecords = e.GSUB.readSubstLookupRecords(n, i, c), o;
    }, e.GSUB.readSubstLookupRecords = function(n, i, s) {
      for (var o = e._bin.readUshort, l = [], c = 0; c < s; c++) l.push(o(n, i), o(n, i + 2)), i += 4;
      return l;
    }, e.GSUB.readChainSubClassSet = function(n, i) {
      var s = e._bin, o = i, l = [], c = s.readUshort(n, i);
      i += 2;
      for (var u = 0; u < c; u++) {
        var f = s.readUshort(n, i);
        i += 2, l.push(e.GSUB.readChainSubClassRule(n, o + f));
      }
      return l;
    }, e.GSUB.readChainSubClassRule = function(n, i) {
      for (var s = e._bin, o = {}, l = ["backtrack", "input", "lookahead"], c = 0; c < l.length; c++) {
        var u = s.readUshort(n, i);
        i += 2, c == 1 && u--, o[l[c]] = s.readUshorts(n, i, u), i += 2 * o[l[c]].length;
      }
      return u = s.readUshort(n, i), i += 2, o.subst = s.readUshorts(n, i, 2 * u), i += 2 * o.subst.length, o;
    }, e.GSUB.readLigatureSet = function(n, i) {
      var s = e._bin, o = i, l = [], c = s.readUshort(n, i);
      i += 2;
      for (var u = 0; u < c; u++) {
        var f = s.readUshort(n, i);
        i += 2, l.push(e.GSUB.readLigature(n, o + f));
      }
      return l;
    }, e.GSUB.readLigature = function(n, i) {
      var s = e._bin, o = { chain: [] };
      o.nglyph = s.readUshort(n, i), i += 2;
      var l = s.readUshort(n, i);
      i += 2;
      for (var c = 0; c < l - 1; c++) o.chain.push(s.readUshort(n, i)), i += 2;
      return o;
    }, e.head = {}, e.head.parse = function(n, i, s) {
      var o = e._bin, l = {};
      return o.readFixed(n, i), i += 4, l.fontRevision = o.readFixed(n, i), i += 4, o.readUint(n, i), i += 4, o.readUint(n, i), i += 4, l.flags = o.readUshort(n, i), i += 2, l.unitsPerEm = o.readUshort(n, i), i += 2, l.created = o.readUint64(n, i), i += 8, l.modified = o.readUint64(n, i), i += 8, l.xMin = o.readShort(n, i), i += 2, l.yMin = o.readShort(n, i), i += 2, l.xMax = o.readShort(n, i), i += 2, l.yMax = o.readShort(n, i), i += 2, l.macStyle = o.readUshort(n, i), i += 2, l.lowestRecPPEM = o.readUshort(n, i), i += 2, l.fontDirectionHint = o.readShort(n, i), i += 2, l.indexToLocFormat = o.readShort(n, i), i += 2, l.glyphDataFormat = o.readShort(n, i), i += 2, l;
    }, e.hhea = {}, e.hhea.parse = function(n, i, s) {
      var o = e._bin, l = {};
      return o.readFixed(n, i), i += 4, l.ascender = o.readShort(n, i), i += 2, l.descender = o.readShort(n, i), i += 2, l.lineGap = o.readShort(n, i), i += 2, l.advanceWidthMax = o.readUshort(n, i), i += 2, l.minLeftSideBearing = o.readShort(n, i), i += 2, l.minRightSideBearing = o.readShort(n, i), i += 2, l.xMaxExtent = o.readShort(n, i), i += 2, l.caretSlopeRise = o.readShort(n, i), i += 2, l.caretSlopeRun = o.readShort(n, i), i += 2, l.caretOffset = o.readShort(n, i), i += 2, i += 8, l.metricDataFormat = o.readShort(n, i), i += 2, l.numberOfHMetrics = o.readUshort(n, i), i += 2, l;
    }, e.hmtx = {}, e.hmtx.parse = function(n, i, s, o) {
      for (var l = e._bin, c = { aWidth: [], lsBearing: [] }, u = 0, f = 0, h = 0; h < o.maxp.numGlyphs; h++) h < o.hhea.numberOfHMetrics && (u = l.readUshort(n, i), i += 2, f = l.readShort(n, i), i += 2), c.aWidth.push(u), c.lsBearing.push(f);
      return c;
    }, e.kern = {}, e.kern.parse = function(n, i, s, o) {
      var l = e._bin, c = l.readUshort(n, i);
      if (i += 2, c == 1) return e.kern.parseV1(n, i - 2, s, o);
      var u = l.readUshort(n, i);
      i += 2;
      for (var f = { glyph1: [], rval: [] }, h = 0; h < u; h++) {
        i += 2, s = l.readUshort(n, i), i += 2;
        var d = l.readUshort(n, i);
        i += 2;
        var g = d >>> 8;
        if ((g &= 15) != 0) throw "unknown kern table format: " + g;
        i = e.kern.readFormat0(n, i, f);
      }
      return f;
    }, e.kern.parseV1 = function(n, i, s, o) {
      var l = e._bin;
      l.readFixed(n, i), i += 4;
      var c = l.readUint(n, i);
      i += 4;
      for (var u = { glyph1: [], rval: [] }, f = 0; f < c; f++) {
        l.readUint(n, i), i += 4;
        var h = l.readUshort(n, i);
        i += 2, l.readUshort(n, i), i += 2;
        var d = h >>> 8;
        if ((d &= 15) != 0) throw "unknown kern table format: " + d;
        i = e.kern.readFormat0(n, i, u);
      }
      return u;
    }, e.kern.readFormat0 = function(n, i, s) {
      var o = e._bin, l = -1, c = o.readUshort(n, i);
      i += 2, o.readUshort(n, i), i += 2, o.readUshort(n, i), i += 2, o.readUshort(n, i), i += 2;
      for (var u = 0; u < c; u++) {
        var f = o.readUshort(n, i);
        i += 2;
        var h = o.readUshort(n, i);
        i += 2;
        var d = o.readShort(n, i);
        i += 2, f != l && (s.glyph1.push(f), s.rval.push({ glyph2: [], vals: [] }));
        var g = s.rval[s.rval.length - 1];
        g.glyph2.push(h), g.vals.push(d), l = f;
      }
      return i;
    }, e.loca = {}, e.loca.parse = function(n, i, s, o) {
      var l = e._bin, c = [], u = o.head.indexToLocFormat, f = o.maxp.numGlyphs + 1;
      if (u == 0) for (var h = 0; h < f; h++) c.push(l.readUshort(n, i + (h << 1)) << 1);
      if (u == 1) for (h = 0; h < f; h++) c.push(l.readUint(n, i + (h << 2)));
      return c;
    }, e.maxp = {}, e.maxp.parse = function(n, i, s) {
      var o = e._bin, l = {}, c = o.readUint(n, i);
      return i += 4, l.numGlyphs = o.readUshort(n, i), i += 2, c == 65536 && (l.maxPoints = o.readUshort(n, i), i += 2, l.maxContours = o.readUshort(n, i), i += 2, l.maxCompositePoints = o.readUshort(n, i), i += 2, l.maxCompositeContours = o.readUshort(n, i), i += 2, l.maxZones = o.readUshort(n, i), i += 2, l.maxTwilightPoints = o.readUshort(n, i), i += 2, l.maxStorage = o.readUshort(n, i), i += 2, l.maxFunctionDefs = o.readUshort(n, i), i += 2, l.maxInstructionDefs = o.readUshort(n, i), i += 2, l.maxStackElements = o.readUshort(n, i), i += 2, l.maxSizeOfInstructions = o.readUshort(n, i), i += 2, l.maxComponentElements = o.readUshort(n, i), i += 2, l.maxComponentDepth = o.readUshort(n, i), i += 2), l;
    }, e.name = {}, e.name.parse = function(n, i, s) {
      var o = e._bin, l = {};
      o.readUshort(n, i), i += 2;
      var c = o.readUshort(n, i);
      i += 2, o.readUshort(n, i);
      for (var u, f = ["copyright", "fontFamily", "fontSubfamily", "ID", "fullName", "version", "postScriptName", "trademark", "manufacturer", "designer", "description", "urlVendor", "urlDesigner", "licence", "licenceURL", "---", "typoFamilyName", "typoSubfamilyName", "compatibleFull", "sampleText", "postScriptCID", "wwsFamilyName", "wwsSubfamilyName", "lightPalette", "darkPalette"], h = i += 2, d = 0; d < c; d++) {
        var g = o.readUshort(n, i);
        i += 2;
        var v = o.readUshort(n, i);
        i += 2;
        var m = o.readUshort(n, i);
        i += 2;
        var p = o.readUshort(n, i);
        i += 2;
        var T = o.readUshort(n, i);
        i += 2;
        var x = o.readUshort(n, i);
        i += 2;
        var _, D = f[p], C = h + 12 * c + x;
        if (g == 0) _ = o.readUnicode(n, C, T / 2);
        else if (g == 3 && v == 0) _ = o.readUnicode(n, C, T / 2);
        else if (v == 0) _ = o.readASCII(n, C, T);
        else if (v == 1) _ = o.readUnicode(n, C, T / 2);
        else if (v == 3) _ = o.readUnicode(n, C, T / 2);
        else {
          if (g != 1) throw "unknown encoding " + v + ", platformID: " + g;
          _ = o.readASCII(n, C, T), console.debug("reading unknown MAC encoding " + v + " as ASCII");
        }
        var A = "p" + g + "," + m.toString(16);
        l[A] == null && (l[A] = {}), l[A][D !== void 0 ? D : p] = _, l[A]._lang = m;
      }
      for (var R in l) if (l[R].postScriptName != null && l[R]._lang == 1033) return l[R];
      for (var R in l) if (l[R].postScriptName != null && l[R]._lang == 0) return l[R];
      for (var R in l) if (l[R].postScriptName != null && l[R]._lang == 3084) return l[R];
      for (var R in l) if (l[R].postScriptName != null) return l[R];
      for (var R in l) {
        u = R;
        break;
      }
      return console.debug("returning name table with languageID " + l[u]._lang), l[u];
    }, e["OS/2"] = {}, e["OS/2"].parse = function(n, i, s) {
      var o = e._bin.readUshort(n, i);
      i += 2;
      var l = {};
      if (o == 0) e["OS/2"].version0(n, i, l);
      else if (o == 1) e["OS/2"].version1(n, i, l);
      else if (o == 2 || o == 3 || o == 4) e["OS/2"].version2(n, i, l);
      else {
        if (o != 5) throw "unknown OS/2 table version: " + o;
        e["OS/2"].version5(n, i, l);
      }
      return l;
    }, e["OS/2"].version0 = function(n, i, s) {
      var o = e._bin;
      return s.xAvgCharWidth = o.readShort(n, i), i += 2, s.usWeightClass = o.readUshort(n, i), i += 2, s.usWidthClass = o.readUshort(n, i), i += 2, s.fsType = o.readUshort(n, i), i += 2, s.ySubscriptXSize = o.readShort(n, i), i += 2, s.ySubscriptYSize = o.readShort(n, i), i += 2, s.ySubscriptXOffset = o.readShort(n, i), i += 2, s.ySubscriptYOffset = o.readShort(n, i), i += 2, s.ySuperscriptXSize = o.readShort(n, i), i += 2, s.ySuperscriptYSize = o.readShort(n, i), i += 2, s.ySuperscriptXOffset = o.readShort(n, i), i += 2, s.ySuperscriptYOffset = o.readShort(n, i), i += 2, s.yStrikeoutSize = o.readShort(n, i), i += 2, s.yStrikeoutPosition = o.readShort(n, i), i += 2, s.sFamilyClass = o.readShort(n, i), i += 2, s.panose = o.readBytes(n, i, 10), i += 10, s.ulUnicodeRange1 = o.readUint(n, i), i += 4, s.ulUnicodeRange2 = o.readUint(n, i), i += 4, s.ulUnicodeRange3 = o.readUint(n, i), i += 4, s.ulUnicodeRange4 = o.readUint(n, i), i += 4, s.achVendID = [o.readInt8(n, i), o.readInt8(n, i + 1), o.readInt8(n, i + 2), o.readInt8(n, i + 3)], i += 4, s.fsSelection = o.readUshort(n, i), i += 2, s.usFirstCharIndex = o.readUshort(n, i), i += 2, s.usLastCharIndex = o.readUshort(n, i), i += 2, s.sTypoAscender = o.readShort(n, i), i += 2, s.sTypoDescender = o.readShort(n, i), i += 2, s.sTypoLineGap = o.readShort(n, i), i += 2, s.usWinAscent = o.readUshort(n, i), i += 2, s.usWinDescent = o.readUshort(n, i), i += 2;
    }, e["OS/2"].version1 = function(n, i, s) {
      var o = e._bin;
      return i = e["OS/2"].version0(n, i, s), s.ulCodePageRange1 = o.readUint(n, i), i += 4, s.ulCodePageRange2 = o.readUint(n, i), i += 4;
    }, e["OS/2"].version2 = function(n, i, s) {
      var o = e._bin;
      return i = e["OS/2"].version1(n, i, s), s.sxHeight = o.readShort(n, i), i += 2, s.sCapHeight = o.readShort(n, i), i += 2, s.usDefault = o.readUshort(n, i), i += 2, s.usBreak = o.readUshort(n, i), i += 2, s.usMaxContext = o.readUshort(n, i), i += 2;
    }, e["OS/2"].version5 = function(n, i, s) {
      var o = e._bin;
      return i = e["OS/2"].version2(n, i, s), s.usLowerOpticalPointSize = o.readUshort(n, i), i += 2, s.usUpperOpticalPointSize = o.readUshort(n, i), i += 2;
    }, e.post = {}, e.post.parse = function(n, i, s) {
      var o = e._bin, l = {};
      return l.version = o.readFixed(n, i), i += 4, l.italicAngle = o.readFixed(n, i), i += 4, l.underlinePosition = o.readShort(n, i), i += 2, l.underlineThickness = o.readShort(n, i), i += 2, l;
    }, e == null && (e = {}), e.U == null && (e.U = {}), e.U.codeToGlyph = function(n, i) {
      var s = n.cmap, o = -1;
      if (s.p0e4 != null ? o = s.p0e4 : s.p3e1 != null ? o = s.p3e1 : s.p1e0 != null ? o = s.p1e0 : s.p0e3 != null && (o = s.p0e3), o == -1) throw "no familiar platform and encoding!";
      var l = s.tables[o];
      if (l.format == 0) return i >= l.map.length ? 0 : l.map[i];
      if (l.format == 4) {
        for (var c = -1, u = 0; u < l.endCount.length; u++) if (i <= l.endCount[u]) {
          c = u;
          break;
        }
        return c == -1 || l.startCount[c] > i ? 0 : 65535 & (l.idRangeOffset[c] != 0 ? l.glyphIdArray[i - l.startCount[c] + (l.idRangeOffset[c] >> 1) - (l.idRangeOffset.length - c)] : i + l.idDelta[c]);
      }
      if (l.format == 12) {
        if (i > l.groups[l.groups.length - 1][1]) return 0;
        for (u = 0; u < l.groups.length; u++) {
          var f = l.groups[u];
          if (f[0] <= i && i <= f[1]) return f[2] + (i - f[0]);
        }
        return 0;
      }
      throw "unknown cmap table format " + l.format;
    }, e.U.glyphToPath = function(n, i) {
      var s = { cmds: [], crds: [] };
      if (n.SVG && n.SVG.entries[i]) {
        var o = n.SVG.entries[i];
        return o == null ? s : (typeof o == "string" && (o = e.SVG.toPath(o), n.SVG.entries[i] = o), o);
      }
      if (n.CFF) {
        var l = { x: 0, y: 0, stack: [], nStems: 0, haveWidth: !1, width: n.CFF.Private ? n.CFF.Private.defaultWidthX : 0, open: !1 }, c = n.CFF, u = n.CFF.Private;
        if (c.ROS) {
          for (var f = 0; c.FDSelect[f + 2] <= i; ) f += 2;
          u = c.FDArray[c.FDSelect[f + 1]].Private;
        }
        e.U._drawCFF(n.CFF.CharStrings[i], l, c, u, s);
      } else n.glyf && e.U._drawGlyf(i, n, s);
      return s;
    }, e.U._drawGlyf = function(n, i, s) {
      var o = i.glyf[n];
      o == null && (o = i.glyf[n] = e.glyf._parseGlyf(i, n)), o != null && (o.noc > -1 ? e.U._simpleGlyph(o, s) : e.U._compoGlyph(o, i, s));
    }, e.U._simpleGlyph = function(n, i) {
      for (var s = 0; s < n.noc; s++) {
        for (var o = s == 0 ? 0 : n.endPts[s - 1] + 1, l = n.endPts[s], c = o; c <= l; c++) {
          var u = c == o ? l : c - 1, f = c == l ? o : c + 1, h = 1 & n.flags[c], d = 1 & n.flags[u], g = 1 & n.flags[f], v = n.xs[c], m = n.ys[c];
          if (c == o) if (h) {
            if (!d) {
              e.U.P.moveTo(i, v, m);
              continue;
            }
            e.U.P.moveTo(i, n.xs[u], n.ys[u]);
          } else d ? e.U.P.moveTo(i, n.xs[u], n.ys[u]) : e.U.P.moveTo(i, (n.xs[u] + v) / 2, (n.ys[u] + m) / 2);
          h ? d && e.U.P.lineTo(i, v, m) : g ? e.U.P.qcurveTo(i, v, m, n.xs[f], n.ys[f]) : e.U.P.qcurveTo(i, v, m, (v + n.xs[f]) / 2, (m + n.ys[f]) / 2);
        }
        e.U.P.closePath(i);
      }
    }, e.U._compoGlyph = function(n, i, s) {
      for (var o = 0; o < n.parts.length; o++) {
        var l = { cmds: [], crds: [] }, c = n.parts[o];
        e.U._drawGlyf(c.glyphIndex, i, l);
        for (var u = c.m, f = 0; f < l.crds.length; f += 2) {
          var h = l.crds[f], d = l.crds[f + 1];
          s.crds.push(h * u.a + d * u.b + u.tx), s.crds.push(h * u.c + d * u.d + u.ty);
        }
        for (f = 0; f < l.cmds.length; f++) s.cmds.push(l.cmds[f]);
      }
    }, e.U._getGlyphClass = function(n, i) {
      var s = e._lctf.getInterval(i, n);
      return s == -1 ? 0 : i[s + 2];
    }, e.U._applySubs = function(n, i, s, o) {
      for (var l = n.length - i - 1, c = 0; c < s.tabs.length; c++) if (s.tabs[c] != null) {
        var u, f = s.tabs[c];
        if (!f.coverage || (u = e._lctf.coverageIndex(f.coverage, n[i])) != -1) {
          if (s.ltype == 1) n[i], f.fmt == 1 ? n[i] = n[i] + f.delta : n[i] = f.newg[u];
          else if (s.ltype == 4) for (var h = f.vals[u], d = 0; d < h.length; d++) {
            var g = h[d], v = g.chain.length;
            if (!(v > l)) {
              for (var m = !0, p = 0, T = 0; T < v; T++) {
                for (; n[i + p + (1 + T)] == -1; ) p++;
                g.chain[T] != n[i + p + (1 + T)] && (m = !1);
              }
              if (m) {
                for (n[i] = g.nglyph, T = 0; T < v + p; T++) n[i + T + 1] = -1;
                break;
              }
            }
          }
          else if (s.ltype == 5 && f.fmt == 2) for (var x = e._lctf.getInterval(f.cDef, n[i]), _ = f.cDef[x + 2], D = f.scset[_], C = 0; C < D.length; C++) {
            var A = D[C], R = A.input;
            if (!(R.length > l)) {
              for (m = !0, T = 0; T < R.length; T++) {
                var E = e._lctf.getInterval(f.cDef, n[i + 1 + T]);
                if (x == -1 && f.cDef[E + 2] != R[T]) {
                  m = !1;
                  break;
                }
              }
              if (m) {
                var S = A.substLookupRecords;
                for (d = 0; d < S.length; d += 2) S[d], S[d + 1];
              }
            }
          }
          else if (s.ltype == 6 && f.fmt == 3) {
            if (!e.U._glsCovered(n, f.backCvg, i - f.backCvg.length) || !e.U._glsCovered(n, f.inptCvg, i) || !e.U._glsCovered(n, f.ahedCvg, i + f.inptCvg.length)) continue;
            var F = f.lookupRec;
            for (C = 0; C < F.length; C += 2) {
              x = F[C];
              var L = o[F[C + 1]];
              e.U._applySubs(n, i + x, L, o);
            }
          }
        }
      }
    }, e.U._glsCovered = function(n, i, s) {
      for (var o = 0; o < i.length; o++)
        if (e._lctf.coverageIndex(i[o], n[s + o]) == -1) return !1;
      return !0;
    }, e.U.glyphsToPath = function(n, i, s) {
      for (var o = { cmds: [], crds: [] }, l = 0, c = 0; c < i.length; c++) {
        var u = i[c];
        if (u != -1) {
          for (var f = c < i.length - 1 && i[c + 1] != -1 ? i[c + 1] : 0, h = e.U.glyphToPath(n, u), d = 0; d < h.crds.length; d += 2) o.crds.push(h.crds[d] + l), o.crds.push(h.crds[d + 1]);
          for (s && o.cmds.push(s), d = 0; d < h.cmds.length; d++) o.cmds.push(h.cmds[d]);
          s && o.cmds.push("X"), l += n.hmtx.aWidth[u], c < i.length - 1 && (l += e.U.getPairAdjustment(n, u, f));
        }
      }
      return o;
    }, e.U.P = {}, e.U.P.moveTo = function(n, i, s) {
      n.cmds.push("M"), n.crds.push(i, s);
    }, e.U.P.lineTo = function(n, i, s) {
      n.cmds.push("L"), n.crds.push(i, s);
    }, e.U.P.curveTo = function(n, i, s, o, l, c, u) {
      n.cmds.push("C"), n.crds.push(i, s, o, l, c, u);
    }, e.U.P.qcurveTo = function(n, i, s, o, l) {
      n.cmds.push("Q"), n.crds.push(i, s, o, l);
    }, e.U.P.closePath = function(n) {
      n.cmds.push("Z");
    }, e.U._drawCFF = function(n, i, s, o, l) {
      for (var c = i.stack, u = i.nStems, f = i.haveWidth, h = i.width, d = i.open, g = 0, v = i.x, m = i.y, p = 0, T = 0, x = 0, _ = 0, D = 0, C = 0, A = 0, R = 0, E = 0, S = 0, F = { val: 0, size: 0 }; g < n.length; ) {
        e.CFF.getCharString(n, g, F);
        var L = F.val;
        if (g += F.size, L == "o1" || L == "o18") c.length % 2 != 0 && !f && (h = c.shift() + o.nominalWidthX), u += c.length >> 1, c.length = 0, f = !0;
        else if (L == "o3" || L == "o23")
          c.length % 2 != 0 && !f && (h = c.shift() + o.nominalWidthX), u += c.length >> 1, c.length = 0, f = !0;
        else if (L == "o4") c.length > 1 && !f && (h = c.shift() + o.nominalWidthX, f = !0), d && e.U.P.closePath(l), m += c.pop(), e.U.P.moveTo(l, v, m), d = !0;
        else if (L == "o5") for (; c.length > 0; ) v += c.shift(), m += c.shift(), e.U.P.lineTo(l, v, m);
        else if (L == "o6" || L == "o7") for (var B = c.length, k = L == "o6", O = 0; O < B; O++) {
          var z = c.shift();
          k ? v += z : m += z, k = !k, e.U.P.lineTo(l, v, m);
        }
        else if (L == "o8" || L == "o24") {
          B = c.length;
          for (var ne = 0; ne + 6 <= B; ) p = v + c.shift(), T = m + c.shift(), x = p + c.shift(), _ = T + c.shift(), v = x + c.shift(), m = _ + c.shift(), e.U.P.curveTo(l, p, T, x, _, v, m), ne += 6;
          L == "o24" && (v += c.shift(), m += c.shift(), e.U.P.lineTo(l, v, m));
        } else {
          if (L == "o11") break;
          if (L == "o1234" || L == "o1235" || L == "o1236" || L == "o1237") L == "o1234" && (T = m, x = (p = v + c.shift()) + c.shift(), S = _ = T + c.shift(), C = _, R = m, v = (A = (D = (E = x + c.shift()) + c.shift()) + c.shift()) + c.shift(), e.U.P.curveTo(l, p, T, x, _, E, S), e.U.P.curveTo(l, D, C, A, R, v, m)), L == "o1235" && (p = v + c.shift(), T = m + c.shift(), x = p + c.shift(), _ = T + c.shift(), E = x + c.shift(), S = _ + c.shift(), D = E + c.shift(), C = S + c.shift(), A = D + c.shift(), R = C + c.shift(), v = A + c.shift(), m = R + c.shift(), c.shift(), e.U.P.curveTo(l, p, T, x, _, E, S), e.U.P.curveTo(l, D, C, A, R, v, m)), L == "o1236" && (p = v + c.shift(), T = m + c.shift(), x = p + c.shift(), S = _ = T + c.shift(), C = _, A = (D = (E = x + c.shift()) + c.shift()) + c.shift(), R = C + c.shift(), v = A + c.shift(), e.U.P.curveTo(l, p, T, x, _, E, S), e.U.P.curveTo(l, D, C, A, R, v, m)), L == "o1237" && (p = v + c.shift(), T = m + c.shift(), x = p + c.shift(), _ = T + c.shift(), E = x + c.shift(), S = _ + c.shift(), D = E + c.shift(), C = S + c.shift(), A = D + c.shift(), R = C + c.shift(), Math.abs(A - v) > Math.abs(R - m) ? v = A + c.shift() : m = R + c.shift(), e.U.P.curveTo(l, p, T, x, _, E, S), e.U.P.curveTo(l, D, C, A, R, v, m));
          else if (L == "o14") {
            if (c.length > 0 && !f && (h = c.shift() + s.nominalWidthX, f = !0), c.length == 4) {
              var q = c.shift(), K = c.shift(), Z = c.shift(), N = c.shift(), Y = e.CFF.glyphBySE(s, Z), ie = e.CFF.glyphBySE(s, N);
              e.U._drawCFF(s.CharStrings[Y], i, s, o, l), i.x = q, i.y = K, e.U._drawCFF(s.CharStrings[ie], i, s, o, l);
            }
            d && (e.U.P.closePath(l), d = !1);
          } else if (L == "o19" || L == "o20")
            c.length % 2 != 0 && !f && (h = c.shift() + o.nominalWidthX), u += c.length >> 1, c.length = 0, f = !0, g += u + 7 >> 3;
          else if (L == "o21") c.length > 2 && !f && (h = c.shift() + o.nominalWidthX, f = !0), m += c.pop(), v += c.pop(), d && e.U.P.closePath(l), e.U.P.moveTo(l, v, m), d = !0;
          else if (L == "o22") c.length > 1 && !f && (h = c.shift() + o.nominalWidthX, f = !0), v += c.pop(), d && e.U.P.closePath(l), e.U.P.moveTo(l, v, m), d = !0;
          else if (L == "o25") {
            for (; c.length > 6; ) v += c.shift(), m += c.shift(), e.U.P.lineTo(l, v, m);
            p = v + c.shift(), T = m + c.shift(), x = p + c.shift(), _ = T + c.shift(), v = x + c.shift(), m = _ + c.shift(), e.U.P.curveTo(l, p, T, x, _, v, m);
          } else if (L == "o26") for (c.length % 2 && (v += c.shift()); c.length > 0; ) p = v, T = m + c.shift(), v = x = p + c.shift(), m = (_ = T + c.shift()) + c.shift(), e.U.P.curveTo(l, p, T, x, _, v, m);
          else if (L == "o27") for (c.length % 2 && (m += c.shift()); c.length > 0; ) T = m, x = (p = v + c.shift()) + c.shift(), _ = T + c.shift(), v = x + c.shift(), m = _, e.U.P.curveTo(l, p, T, x, _, v, m);
          else if (L == "o10" || L == "o29") {
            var b = L == "o10" ? o : s;
            if (c.length == 0) console.debug("error: empty stack");
            else {
              var U = c.pop(), G = b.Subrs[U + b.Bias];
              i.x = v, i.y = m, i.nStems = u, i.haveWidth = f, i.width = h, i.open = d, e.U._drawCFF(G, i, s, o, l), v = i.x, m = i.y, u = i.nStems, f = i.haveWidth, h = i.width, d = i.open;
            }
          } else if (L == "o30" || L == "o31") {
            var I = c.length, V = (ne = 0, L == "o31");
            for (ne += I - (B = -3 & I); ne < B; ) V ? (T = m, x = (p = v + c.shift()) + c.shift(), m = (_ = T + c.shift()) + c.shift(), B - ne == 5 ? (v = x + c.shift(), ne++) : v = x, V = !1) : (p = v, T = m + c.shift(), x = p + c.shift(), _ = T + c.shift(), v = x + c.shift(), B - ne == 5 ? (m = _ + c.shift(), ne++) : m = _, V = !0), e.U.P.curveTo(l, p, T, x, _, v, m), ne += 4;
          } else {
            if ((L + "").charAt(0) == "o") throw console.debug("Unknown operation: " + L, n), L;
            c.push(L);
          }
        }
      }
      i.x = v, i.y = m, i.nStems = u, i.haveWidth = f, i.width = h, i.open = d;
    };
    var t = e, r = { Typr: t };
    return a.Typr = t, a.default = r, Object.defineProperty(a, "__esModule", { value: !0 }), a;
  }({}).Typr;
}
/*!
Custom bundle of woff2otf (https://github.com/arty-name/woff2otf) with fflate
(https://github.com/101arrowz/fflate) for use in Troika text rendering. 
Original licenses apply: 
- fflate: https://github.com/101arrowz/fflate/blob/master/LICENSE (MIT)
- woff2otf.js: https://github.com/arty-name/woff2otf/blob/master/woff2otf.js (Apache2)
*/
function Xp() {
  return function(a) {
    var e = Uint8Array, t = Uint16Array, r = Uint32Array, n = new e([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0]), i = new e([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0]), s = new e([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), o = function(L, B) {
      for (var k = new t(31), O = 0; O < 31; ++O) k[O] = B += 1 << L[O - 1];
      var z = new r(k[30]);
      for (O = 1; O < 30; ++O) for (var ne = k[O]; ne < k[O + 1]; ++ne) z[ne] = ne - k[O] << 5 | O;
      return [k, z];
    }, l = o(n, 2), c = l[0], u = l[1];
    c[28] = 258, u[258] = 28;
    for (var f = o(i, 0)[0], h = new t(32768), d = 0; d < 32768; ++d) {
      var g = (43690 & d) >>> 1 | (21845 & d) << 1;
      g = (61680 & (g = (52428 & g) >>> 2 | (13107 & g) << 2)) >>> 4 | (3855 & g) << 4, h[d] = ((65280 & g) >>> 8 | (255 & g) << 8) >>> 1;
    }
    var v = function(L, B, k) {
      for (var O = L.length, z = 0, ne = new t(B); z < O; ++z) ++ne[L[z] - 1];
      var q, K = new t(B);
      for (z = 0; z < B; ++z) K[z] = K[z - 1] + ne[z - 1] << 1;
      {
        q = new t(1 << B);
        var Z = 15 - B;
        for (z = 0; z < O; ++z) if (L[z]) for (var N = z << 4 | L[z], Y = B - L[z], ie = K[L[z] - 1]++ << Y, b = ie | (1 << Y) - 1; ie <= b; ++ie) q[h[ie] >>> Z] = N;
      }
      return q;
    }, m = new e(288);
    for (d = 0; d < 144; ++d) m[d] = 8;
    for (d = 144; d < 256; ++d) m[d] = 9;
    for (d = 256; d < 280; ++d) m[d] = 7;
    for (d = 280; d < 288; ++d) m[d] = 8;
    var p = new e(32);
    for (d = 0; d < 32; ++d) p[d] = 5;
    var T = v(m, 9), x = v(p, 5), _ = function(L) {
      for (var B = L[0], k = 1; k < L.length; ++k) L[k] > B && (B = L[k]);
      return B;
    }, D = function(L, B, k) {
      var O = B / 8 | 0;
      return (L[O] | L[O + 1] << 8) >> (7 & B) & k;
    }, C = function(L, B) {
      var k = B / 8 | 0;
      return (L[k] | L[k + 1] << 8 | L[k + 2] << 16) >> (7 & B);
    }, A = ["unexpected EOF", "invalid block type", "invalid length/literal", "invalid distance", "stream finished", "no stream handler", , "no callback", "invalid UTF-8 data", "extra field too long", "date not in range 1980-2099", "filename too long", "stream finishing", "invalid zip data"], R = function(L, B, k) {
      var O = new Error(B || A[L]);
      if (O.code = L, Error.captureStackTrace && Error.captureStackTrace(O, R), !k) throw O;
      return O;
    }, E = function(L, B, k) {
      var O = L.length;
      if (!O || k && !k.l && O < 5) return B || new e(0);
      var z = !B || k, ne = !k || k.i;
      k || (k = {}), B || (B = new e(3 * O));
      var q, K = function(Me) {
        var ze = B.length;
        if (Me > ze) {
          var Fe = new e(Math.max(2 * ze, Me));
          Fe.set(B), B = Fe;
        }
      }, Z = k.f || 0, N = k.p || 0, Y = k.b || 0, ie = k.l, b = k.d, U = k.m, G = k.n, I = 8 * O;
      do {
        if (!ie) {
          k.f = Z = D(L, N, 1);
          var V = D(L, N + 1, 3);
          if (N += 3, !V) {
            var re = L[(me = ((q = N) / 8 | 0) + (7 & q && 1) + 4) - 4] | L[me - 3] << 8, he = me + re;
            if (he > O) {
              ne && R(0);
              break;
            }
            z && K(Y + re), B.set(L.subarray(me, he), Y), k.b = Y += re, k.p = N = 8 * he;
            continue;
          }
          if (V == 1) ie = T, b = x, U = 9, G = 5;
          else if (V == 2) {
            var fe = D(L, N, 31) + 257, W = D(L, N + 10, 15) + 4, ce = fe + D(L, N + 5, 31) + 1;
            N += 14;
            for (var P = new e(ce), pe = new e(19), ae = 0; ae < W; ++ae) pe[s[ae]] = D(L, N + 3 * ae, 7);
            N += 3 * W;
            var ve = _(pe), te = (1 << ve) - 1, Te = v(pe, ve);
            for (ae = 0; ae < ce; ) {
              var me, M = Te[D(L, N, te)];
              if (N += 15 & M, (me = M >>> 4) < 16) P[ae++] = me;
              else {
                var y = 0, H = 0;
                for (me == 16 ? (H = 3 + D(L, N, 3), N += 2, y = P[ae - 1]) : me == 17 ? (H = 3 + D(L, N, 7), N += 3) : me == 18 && (H = 11 + D(L, N, 127), N += 7); H--; ) P[ae++] = y;
              }
            }
            var $ = P.subarray(0, fe), ee = P.subarray(fe);
            U = _($), G = _(ee), ie = v($, U), b = v(ee, G);
          } else R(1);
          if (N > I) {
            ne && R(0);
            break;
          }
        }
        z && K(Y + 131072);
        for (var oe = (1 << U) - 1, Se = (1 << G) - 1, de = N; ; de = N) {
          var xe = (y = ie[C(L, N) & oe]) >>> 4;
          if ((N += 15 & y) > I) {
            ne && R(0);
            break;
          }
          if (y || R(2), xe < 256) B[Y++] = xe;
          else {
            if (xe == 256) {
              de = N, ie = null;
              break;
            }
            var De = xe - 254;
            if (xe > 264) {
              var ye = n[ae = xe - 257];
              De = D(L, N, (1 << ye) - 1) + c[ae], N += ye;
            }
            var Re = b[C(L, N) & Se], Pe = Re >>> 4;
            if (Re || R(3), N += 15 & Re, ee = f[Pe], Pe > 3 && (ye = i[Pe], ee += C(L, N) & (1 << ye) - 1, N += ye), N > I) {
              ne && R(0);
              break;
            }
            z && K(Y + 131072);
            for (var Ue = Y + De; Y < Ue; Y += 4) B[Y] = B[Y - ee], B[Y + 1] = B[Y + 1 - ee], B[Y + 2] = B[Y + 2 - ee], B[Y + 3] = B[Y + 3 - ee];
            Y = Ue;
          }
        }
        k.l = ie, k.p = de, k.b = Y, ie && (Z = 1, k.m = U, k.d = b, k.n = G);
      } while (!Z);
      return Y == B.length ? B : function(Me, ze, Fe) {
        (Fe == null || Fe > Me.length) && (Fe = Me.length);
        var je = new (Me instanceof t ? t : Me instanceof r ? r : e)(Fe - ze);
        return je.set(Me.subarray(ze, Fe)), je;
      }(B, 0, Y);
    }, S = new e(0), F = typeof TextDecoder < "u" && new TextDecoder();
    try {
      F.decode(S, { stream: !0 });
    } catch {
    }
    return a.convert_streams = function(L) {
      var B = new DataView(L), k = 0;
      function O() {
        var fe = B.getUint16(k);
        return k += 2, fe;
      }
      function z() {
        var fe = B.getUint32(k);
        return k += 4, fe;
      }
      function ne(fe) {
        re.setUint16(he, fe), he += 2;
      }
      function q(fe) {
        re.setUint32(he, fe), he += 4;
      }
      for (var K = { signature: z(), flavor: z(), length: z(), numTables: O(), reserved: O(), totalSfntSize: z(), majorVersion: O(), minorVersion: O(), metaOffset: z(), metaLength: z(), metaOrigLength: z(), privOffset: z(), privLength: z() }, Z = 0; Math.pow(2, Z) <= K.numTables; ) Z++;
      Z--;
      for (var N = 16 * Math.pow(2, Z), Y = 16 * K.numTables - N, ie = 12, b = [], U = 0; U < K.numTables; U++) b.push({ tag: z(), offset: z(), compLength: z(), origLength: z(), origChecksum: z() }), ie += 16;
      var G, I = new Uint8Array(12 + 16 * b.length + b.reduce(function(fe, W) {
        return fe + W.origLength + 4;
      }, 0)), V = I.buffer, re = new DataView(V), he = 0;
      return q(K.flavor), ne(K.numTables), ne(N), ne(Z), ne(Y), b.forEach(function(fe) {
        q(fe.tag), q(fe.origChecksum), q(ie), q(fe.origLength), fe.outOffset = ie, (ie += fe.origLength) % 4 != 0 && (ie += 4 - ie % 4);
      }), b.forEach(function(fe) {
        var W, ce = L.slice(fe.offset, fe.offset + fe.compLength);
        if (fe.compLength != fe.origLength) {
          var P = new Uint8Array(fe.origLength);
          W = new Uint8Array(ce, 2), E(W, P);
        } else P = new Uint8Array(ce);
        I.set(P, fe.outOffset);
        var pe = 0;
        (ie = fe.outOffset + fe.origLength) % 4 != 0 && (pe = 4 - ie % 4), I.set(new Uint8Array(pe).buffer, fe.outOffset + fe.origLength), G = ie + pe;
      }), V.slice(0, G);
    }, Object.defineProperty(a, "__esModule", { value: !0 }), a;
  }({}).convert_streams;
}
function qp(a, e) {
  const t = {
    M: 2,
    L: 2,
    Q: 4,
    C: 6,
    Z: 0
  }, r = { C: "18g,ca,368,1kz", D: "17k,6,2,2+4,5+c,2+6,2+1,10+1,9+f,j+11,2+1,a,2,2+1,15+2,3,j+2,6+3,2+8,2,2,2+1,w+a,4+e,3+3,2,3+2,3+5,23+w,2f+4,3,2+9,2,b,2+3,3,1k+9,6+1,3+1,2+2,2+d,30g,p+y,1,1+1g,f+x,2,sd2+1d,jf3+4,f+3,2+4,2+2,b+3,42,2,4+2,2+1,2,3,t+1,9f+w,2,el+2,2+g,d+2,2l,2+1,5,3+1,2+1,2,3,6,16wm+1v", R: "17m+3,2,2,6+3,m,15+2,2+2,h+h,13,3+8,2,2,3+1,2,p+1,x,5+4,5,a,2,2,3,u,c+2,g+1,5,2+1,4+1,5j,6+1,2,b,2+2,f,2+1,1s+2,2,3+1,7,1ez0,2,2+1,4+4,b,4,3,b,42,2+2,4,3,2+1,2,o+3,ae,ep,x,2o+2,3+1,3,5+1,6", L: "x9u,jff,a,fd,jv", T: "4t,gj+33,7o+4,1+1,7c+18,2,2+1,2+1,2,21+a,2,1b+k,h,2u+6,3+5,3+1,2+3,y,2,v+q,2k+a,1n+8,a,p+3,2+8,2+2,2+4,18+2,3c+e,2+v,1k,2,5+7,5,4+6,b+1,u,1n,5+3,9,l+1,r,3+1,1m,5+1,5+1,3+2,4,v+1,4,c+1,1m,5+4,2+1,5,l+1,n+5,2,1n,3,2+3,9,8+1,c+1,v,1q,d,1f,4,1m+2,6+2,2+3,8+1,c+1,u,1n,3,7,6+1,l+1,t+1,1m+1,5+3,9,l+1,u,21,8+2,2,2j,3+6,d+7,2r,3+8,c+5,23+1,s,2,2,1k+d,2+4,2+1,6+a,2+z,a,2v+3,2+5,2+1,3+1,q+1,5+2,h+3,e,3+1,7,g,jk+2,qb+2,u+2,u+1,v+1,1t+1,2+6,9,3+a,a,1a+2,3c+1,z,3b+2,5+1,a,7+2,64+1,3,1n,2+6,2,2,3+7,7+9,3,1d+d,1,1+1,1s+3,1d,2+4,2,6,15+8,d+1,x+3,3+1,2+2,1l,2+1,4,2+2,1n+7,3+1,49+2,2+c,2+6,5,7,4+1,5j+1l,2+4,ek,3+1,r+4,1e+4,6+5,2p+c,1+3,1,1+2,1+b,2db+2,3y,2p+v,ff+3,30+1,n9x,1+2,2+9,x+1,29+1,7l,4,5,q+1,6,48+1,r+h,e,13+7,q+a,1b+2,1d,3+3,3+1,14,1w+5,3+1,3+1,d,9,1c,1g,2+2,3+1,6+1,2,17+1,9,6n,3,5,fn5,ki+f,h+f,5s,6y+2,ea,6b,46+4,1af+2,2+1,6+3,15+2,5,4m+1,fy+3,as+1,4a+a,4x,1j+e,1l+2,1e+3,3+1,1y+2,11+4,2+7,1r,d+1,1h+8,b+3,3,2o+2,3,2+1,7,4h,4+7,m+1,1m+1,4,12+6,4+4,5g+7,3+2,2,o,2d+5,2,5+1,2+1,6n+3,7+1,2+1,s+1,2e+7,3,2+1,2z,2,3+5,2,2u+2,3+3,2+4,78+8,2+1,75+1,2,5,41+3,3+1,5,x+9,15+5,3+3,9,a+5,3+2,1b+c,2+1,bb+6,2+5,2,2b+l,3+6,2+1,2+1,3f+5,4,2+1,2+6,2,21+1,4,2,9o+1,470+8,at4+4,1o+6,t5,1s+3,2a,f5l+1,2+3,43o+2,a+7,1+7,3+6,v+3,45+2,1j0+1i,5+1d,9,f,n+4,2+e,11t+6,2+g,3+6,2+1,2+4,7a+6,c6+3,15t+6,32+6,1,gzau,v+2n,3l+6n" }, n = 1, i = 2, s = 4, o = 8, l = 16, c = 32;
  let u;
  function f(A) {
    if (!u) {
      const R = {
        R: i,
        L: n,
        D: s,
        C: l,
        U: c,
        T: o
      };
      u = /* @__PURE__ */ new Map();
      for (let E in r) {
        let S = 0;
        r[E].split(",").forEach((F) => {
          let [L, B] = F.split("+");
          L = parseInt(L, 36), B = B ? parseInt(B, 36) : 0, u.set(S += L, R[E]);
          for (let k = B; k--; )
            u.set(++S, R[E]);
        });
      }
    }
    return u.get(A) || c;
  }
  const h = 1, d = 2, g = 3, v = 4, m = [null, "isol", "init", "fina", "medi"];
  function p(A) {
    const R = new Uint8Array(A.length);
    let E = c, S = h, F = -1;
    for (let L = 0; L < A.length; L++) {
      const B = A.codePointAt(L);
      let k = f(B) | 0, O = h;
      k & o || (E & (n | s | l) ? k & (i | s | l) ? (O = g, (S === h || S === g) && R[F]++) : k & (n | c) && (S === d || S === v) && R[F]-- : E & (i | c) && (S === d || S === v) && R[F]--, S = R[L] = O, E = k, F = L, B > 65535 && L++);
    }
    return R;
  }
  function T(A, R) {
    const E = [];
    for (let F = 0; F < R.length; F++) {
      const L = R.codePointAt(F);
      L > 65535 && F++, E.push(a.U.codeToGlyph(A, L));
    }
    const S = A.GSUB;
    if (S) {
      const { lookupList: F, featureList: L } = S;
      let B;
      const k = /^(rlig|liga|mset|isol|init|fina|medi|half|pres|blws|ccmp)$/, O = [];
      L.forEach((z) => {
        if (k.test(z.tag))
          for (let ne = 0; ne < z.tab.length; ne++) {
            if (O[z.tab[ne]]) continue;
            O[z.tab[ne]] = !0;
            const q = F[z.tab[ne]], K = /^(isol|init|fina|medi)$/.test(z.tag);
            K && !B && (B = p(R));
            for (let Z = 0; Z < E.length; Z++)
              (!B || !K || m[B[Z]] === z.tag) && a.U._applySubs(E, Z, q, F);
          }
      });
    }
    return E;
  }
  function x(A, R) {
    const E = new Int16Array(R.length * 3);
    let S = 0;
    for (; S < R.length; S++) {
      const k = R[S];
      if (k === -1) continue;
      E[S * 3 + 2] = A.hmtx.aWidth[k];
      const O = A.GPOS;
      if (O) {
        const z = O.lookupList;
        for (let ne = 0; ne < z.length; ne++) {
          const q = z[ne];
          for (let K = 0; K < q.tabs.length; K++) {
            const Z = q.tabs[K];
            if (q.ltype === 1) {
              if (a._lctf.coverageIndex(Z.coverage, k) !== -1 && Z.pos) {
                B(Z.pos, S);
                break;
              }
            } else if (q.ltype === 2) {
              let N = null, Y = F();
              if (Y !== -1) {
                const ie = a._lctf.coverageIndex(Z.coverage, R[Y]);
                if (ie !== -1) {
                  if (Z.fmt === 1) {
                    const b = Z.pairsets[ie];
                    for (let U = 0; U < b.length; U++)
                      b[U].gid2 === k && (N = b[U]);
                  } else if (Z.fmt === 2) {
                    const b = a.U._getGlyphClass(R[Y], Z.classDef1), U = a.U._getGlyphClass(k, Z.classDef2);
                    N = Z.matrix[b][U];
                  }
                  if (N) {
                    N.val1 && B(N.val1, Y), N.val2 && B(N.val2, S);
                    break;
                  }
                }
              }
            } else if (q.ltype === 4) {
              const N = a._lctf.coverageIndex(Z.markCoverage, k);
              if (N !== -1) {
                const Y = F(L), ie = Y === -1 ? -1 : a._lctf.coverageIndex(Z.baseCoverage, R[Y]);
                if (ie !== -1) {
                  const b = Z.markArray[N], U = Z.baseArray[ie][b.markClass];
                  E[S * 3] = U.x - b.x + E[Y * 3] - E[Y * 3 + 2], E[S * 3 + 1] = U.y - b.y + E[Y * 3 + 1];
                  break;
                }
              }
            } else if (q.ltype === 6) {
              const N = a._lctf.coverageIndex(Z.mark1Coverage, k);
              if (N !== -1) {
                const Y = F();
                if (Y !== -1) {
                  const ie = R[Y];
                  if (_(A, ie) === 3) {
                    const b = a._lctf.coverageIndex(Z.mark2Coverage, ie);
                    if (b !== -1) {
                      const U = Z.mark1Array[N], G = Z.mark2Array[b][U.markClass];
                      E[S * 3] = G.x - U.x + E[Y * 3] - E[Y * 3 + 2], E[S * 3 + 1] = G.y - U.y + E[Y * 3 + 1];
                      break;
                    }
                  }
                }
              }
            }
          }
        }
      } else if (A.kern && !A.cff) {
        const z = F();
        if (z !== -1) {
          const ne = A.kern.glyph1.indexOf(R[z]);
          if (ne !== -1) {
            const q = A.kern.rval[ne].glyph2.indexOf(k);
            q !== -1 && (E[z * 3 + 2] += A.kern.rval[ne].vals[q]);
          }
        }
      }
    }
    return E;
    function F(k) {
      for (let O = S - 1; O >= 0; O--)
        if (R[O] !== -1 && (!k || k(R[O])))
          return O;
      return -1;
    }
    function L(k) {
      return _(A, k) === 1;
    }
    function B(k, O) {
      for (let z = 0; z < 3; z++)
        E[O * 3 + z] += k[z] || 0;
    }
  }
  function _(A, R) {
    const E = A.GDEF && A.GDEF.glyphClassDef;
    return E ? a.U._getGlyphClass(R, E) : 0;
  }
  function D(...A) {
    for (let R = 0; R < A.length; R++)
      if (typeof A[R] == "number")
        return A[R];
  }
  function C(A) {
    const R = /* @__PURE__ */ Object.create(null), E = A["OS/2"], S = A.hhea, F = A.head.unitsPerEm, L = D(E && E.sTypoAscender, S && S.ascender, F), B = {
      unitsPerEm: F,
      ascender: L,
      descender: D(E && E.sTypoDescender, S && S.descender, 0),
      capHeight: D(E && E.sCapHeight, L),
      xHeight: D(E && E.sxHeight, L),
      lineGap: D(E && E.sTypoLineGap, S && S.lineGap),
      supportsCodePoint(k) {
        return a.U.codeToGlyph(A, k) > 0;
      },
      forEachGlyph(k, O, z, ne) {
        let q = 0;
        const K = 1 / B.unitsPerEm * O, Z = T(A, k);
        let N = 0;
        const Y = x(A, Z);
        return Z.forEach((ie, b) => {
          if (ie !== -1) {
            let U = R[ie];
            if (!U) {
              const { cmds: G, crds: I } = a.U.glyphToPath(A, ie);
              let V = "", re = 0;
              for (let P = 0, pe = G.length; P < pe; P++) {
                const ae = t[G[P]];
                V += G[P];
                for (let ve = 1; ve <= ae; ve++)
                  V += (ve > 1 ? "," : "") + I[re++];
              }
              let he, fe, W, ce;
              if (I.length) {
                he = fe = 1 / 0, W = ce = -1 / 0;
                for (let P = 0, pe = I.length; P < pe; P += 2) {
                  let ae = I[P], ve = I[P + 1];
                  ae < he && (he = ae), ve < fe && (fe = ve), ae > W && (W = ae), ve > ce && (ce = ve);
                }
              } else
                he = W = fe = ce = 0;
              U = R[ie] = {
                index: ie,
                advanceWidth: A.hmtx.aWidth[ie],
                xMin: he,
                yMin: fe,
                xMax: W,
                yMax: ce,
                path: V
              };
            }
            ne.call(
              null,
              U,
              q + Y[b * 3] * K,
              Y[b * 3 + 1] * K,
              N
            ), q += Y[b * 3 + 2] * K, z && (q += z * O);
          }
          N += k.codePointAt(N) > 65535 ? 2 : 1;
        }), q;
      }
    };
    return B;
  }
  return function(R) {
    const E = new Uint8Array(R, 0, 4), S = a._bin.readASCII(E, 0, 4);
    if (S === "wOFF")
      R = e(R);
    else if (S === "wOF2")
      throw new Error("woff2 fonts not supported");
    return C(a.parse(R)[0]);
  };
}
const Yp = /* @__PURE__ */ xi({
  name: "Typr Font Parser",
  dependencies: [Wp, Xp, qp],
  init(a, e, t) {
    const r = a(), n = e();
    return t(r, n);
  }
});
/*!
Custom bundle of @unicode-font-resolver/client v1.0.2 (https://github.com/lojjic/unicode-font-resolver)
for use in Troika text rendering. 
Original MIT license applies
*/
function jp() {
  return function(a) {
    var e = function() {
      this.buckets = /* @__PURE__ */ new Map();
    };
    e.prototype.add = function(x) {
      var _ = x >> 5;
      this.buckets.set(_, (this.buckets.get(_) || 0) | 1 << (31 & x));
    }, e.prototype.has = function(x) {
      var _ = this.buckets.get(x >> 5);
      return _ !== void 0 && (_ & 1 << (31 & x)) != 0;
    }, e.prototype.serialize = function() {
      var x = [];
      return this.buckets.forEach(function(_, D) {
        x.push((+D).toString(36) + ":" + _.toString(36));
      }), x.join(",");
    }, e.prototype.deserialize = function(x) {
      var _ = this;
      this.buckets.clear(), x.split(",").forEach(function(D) {
        var C = D.split(":");
        _.buckets.set(parseInt(C[0], 36), parseInt(C[1], 36));
      });
    };
    var t = Math.pow(2, 8), r = t - 1, n = ~r;
    function i(x) {
      var _ = function(C) {
        return C & n;
      }(x).toString(16), D = function(C) {
        return (C & n) + t - 1;
      }(x).toString(16);
      return "codepoint-index/plane" + (x >> 16) + "/" + _ + "-" + D + ".json";
    }
    function s(x, _) {
      var D = x & r, C = _.codePointAt(D / 6 | 0);
      return ((C = (C || 48) - 48) & 1 << D % 6) != 0;
    }
    function o(x, _) {
      var D;
      (D = x, D.replace(/U\+/gi, "").replace(/^,+|,+$/g, "").split(/,+/).map(function(C) {
        return C.split("-").map(function(A) {
          return parseInt(A.trim(), 16);
        });
      })).forEach(function(C) {
        var A = C[0], R = C[1];
        R === void 0 && (R = A), _(A, R);
      });
    }
    function l(x, _) {
      o(x, function(D, C) {
        for (var A = D; A <= C; A++) _(A);
      });
    }
    var c = {}, u = {}, f = /* @__PURE__ */ new WeakMap(), h = "https://cdn.jsdelivr.net/gh/lojjic/unicode-font-resolver@v1.0.1/packages/data";
    function d(x) {
      var _ = f.get(x);
      return _ || (_ = new e(), l(x.ranges, function(D) {
        return _.add(D);
      }), f.set(x, _)), _;
    }
    var g, v = /* @__PURE__ */ new Map();
    function m(x, _, D) {
      return x[_] ? _ : x[D] ? D : function(C) {
        for (var A in C) return A;
      }(x);
    }
    function p(x, _) {
      var D = _;
      if (!x.includes(D)) {
        D = 1 / 0;
        for (var C = 0; C < x.length; C++) Math.abs(x[C] - _) < Math.abs(D - _) && (D = x[C]);
      }
      return D;
    }
    function T(x) {
      return g || (g = /* @__PURE__ */ new Set(), l("9-D,20,85,A0,1680,2000-200A,2028-202F,205F,3000", function(_) {
        g.add(_);
      })), g.has(x);
    }
    return a.CodePointSet = e, a.clearCache = function() {
      c = {}, u = {};
    }, a.getFontsForString = function(x, _) {
      _ === void 0 && (_ = {});
      var D, C = _.lang;
      C === void 0 && (C = new RegExp("\\p{Script=Hangul}", "u").test(D = x) ? "ko" : new RegExp("\\p{Script=Hiragana}|\\p{Script=Katakana}", "u").test(D) ? "ja" : "en");
      var A = _.category;
      A === void 0 && (A = "sans-serif");
      var R = _.style;
      R === void 0 && (R = "normal");
      var E = _.weight;
      E === void 0 && (E = 400);
      var S = (_.dataUrl || h).replace(/\/$/g, ""), F = /* @__PURE__ */ new Map(), L = new Uint8Array(x.length), B = {}, k = {}, O = new Array(x.length), z = /* @__PURE__ */ new Map(), ne = !1;
      function q(N) {
        var Y = v.get(N);
        return Y || (Y = fetch(S + "/" + N).then(function(ie) {
          if (!ie.ok) throw new Error(ie.statusText);
          return ie.json().then(function(b) {
            if (!Array.isArray(b) || b[0] !== 1) throw new Error("Incorrect schema version; need 1, got " + b[0]);
            return b[1];
          });
        }).catch(function(ie) {
          if (S !== h) return ne || (console.error('unicode-font-resolver: Failed loading from dataUrl "' + S + '", trying default CDN. ' + ie.message), ne = !0), S = h, v.delete(N), q(N);
          throw ie;
        }), v.set(N, Y)), Y;
      }
      for (var K = function(N) {
        var Y = x.codePointAt(N), ie = i(Y);
        O[N] = ie, c[ie] || z.has(ie) || z.set(ie, q(ie).then(function(b) {
          c[ie] = b;
        })), Y > 65535 && (N++, Z = N);
      }, Z = 0; Z < x.length; Z++) K(Z);
      return Promise.all(z.values()).then(function() {
        z.clear();
        for (var N = function(ie) {
          var b = x.codePointAt(ie), U = null, G = c[O[ie]], I = void 0;
          for (var V in G) {
            var re = k[V];
            if (re === void 0 && (re = k[V] = new RegExp(V).test(C || "en")), re) {
              for (var he in I = V, G[V]) if (s(b, G[V][he])) {
                U = he;
                break;
              }
              break;
            }
          }
          if (!U) {
            e: for (var fe in G) if (fe !== I) {
              for (var W in G[fe]) if (s(b, G[fe][W])) {
                U = W;
                break e;
              }
            }
          }
          U || (console.debug("No font coverage for U+" + b.toString(16)), U = "latin"), O[ie] = U, u[U] || z.has(U) || z.set(U, q("font-meta/" + U + ".json").then(function(ce) {
            u[U] = ce;
          })), b > 65535 && (ie++, Y = ie);
        }, Y = 0; Y < x.length; Y++) N(Y);
        return Promise.all(z.values());
      }).then(function() {
        for (var N, Y = null, ie = 0; ie < x.length; ie++) {
          var b = x.codePointAt(ie);
          if (Y && (T(b) || d(Y).has(b))) L[ie] = L[ie - 1];
          else {
            Y = u[O[ie]];
            var U = B[Y.id];
            if (!U) {
              var G = Y.typeforms, I = m(G, A, "sans-serif"), V = m(G[I], R, "normal"), re = p((N = G[I]) === null || N === void 0 ? void 0 : N[V], E);
              U = B[Y.id] = S + "/font-files/" + Y.id + "/" + I + "." + V + "." + re + ".woff";
            }
            var he = F.get(U);
            he == null && (he = F.size, F.set(U, he)), L[ie] = he;
          }
          b > 65535 && (ie++, L[ie] = L[ie - 1]);
        }
        return { fontUrls: Array.from(F.keys()), chars: L };
      });
    }, Object.defineProperty(a, "__esModule", { value: !0 }), a;
  }({});
}
function Zp(a, e) {
  const t = /* @__PURE__ */ Object.create(null), r = /* @__PURE__ */ Object.create(null);
  function n(s, o) {
    const l = (c) => {
      console.error(`Failure loading font ${s}`, c);
    };
    try {
      const c = new XMLHttpRequest();
      c.open("get", s, !0), c.responseType = "arraybuffer", c.onload = function() {
        if (c.status >= 400)
          l(new Error(c.statusText));
        else if (c.status > 0)
          try {
            const u = a(c.response);
            u.src = s, o(u);
          } catch (u) {
            l(u);
          }
      }, c.onerror = l, c.send();
    } catch (c) {
      l(c);
    }
  }
  function i(s, o) {
    let l = t[s];
    l ? o(l) : r[s] ? r[s].push(o) : (r[s] = [o], n(s, (c) => {
      c.src = s, t[s] = c, r[s].forEach((u) => u(c)), delete r[s];
    }));
  }
  return function(s, o, {
    lang: l,
    fonts: c = [],
    style: u = "normal",
    weight: f = "normal",
    unicodeFontsURL: h
  } = {}) {
    const d = new Uint8Array(s.length), g = [];
    s.length || T();
    const v = /* @__PURE__ */ new Map(), m = [];
    if (u !== "italic" && (u = "normal"), typeof f != "number" && (f = f === "bold" ? 700 : 400), c && !Array.isArray(c) && (c = [c]), c = c.slice().filter((_) => !_.lang || _.lang.test(l)).reverse(), c.length) {
      let A = 0;
      (function R(E = 0) {
        for (let S = E, F = s.length; S < F; S++) {
          const L = s.codePointAt(S);
          if (A === 1 && g[d[S - 1]].supportsCodePoint(L) || /\s/.test(s[S]))
            d[S] = d[S - 1], A === 2 && (m[m.length - 1][1] = S);
          else
            for (let B = d[S], k = c.length; B <= k; B++)
              if (B === k) {
                const O = A === 2 ? m[m.length - 1] : m[m.length] = [S, S];
                O[1] = S, A = 2;
              } else {
                d[S] = B;
                const { src: O, unicodeRange: z } = c[B];
                if (!z || x(L, z)) {
                  const ne = t[O];
                  if (!ne) {
                    i(O, () => {
                      R(S);
                    });
                    return;
                  }
                  if (ne.supportsCodePoint(L)) {
                    let q = v.get(ne);
                    typeof q != "number" && (q = g.length, g.push(ne), v.set(ne, q)), d[S] = q, A = 1;
                    break;
                  }
                }
              }
          L > 65535 && S + 1 < F && (d[S + 1] = d[S], S++, A === 2 && (m[m.length - 1][1] = S));
        }
        p();
      })();
    } else
      m.push([0, s.length - 1]), p();
    function p() {
      if (m.length) {
        const _ = m.map((D) => s.substring(D[0], D[1] + 1)).join(`
`);
        e.getFontsForString(_, {
          lang: l || void 0,
          style: u,
          weight: f,
          dataUrl: h
        }).then(({ fontUrls: D, chars: C }) => {
          const A = g.length;
          let R = 0;
          m.forEach((S) => {
            for (let F = 0, L = S[1] - S[0]; F <= L; F++)
              d[S[0] + F] = C[R++] + A;
            R++;
          });
          let E = 0;
          D.forEach((S, F) => {
            i(S, (L) => {
              g[F + A] = L, ++E === D.length && T();
            });
          });
        });
      } else
        T();
    }
    function T() {
      o({
        chars: d,
        fonts: g
      });
    }
    function x(_, D) {
      for (let C = 0; C < D.length; C++) {
        const [A, R = A] = D[C];
        if (A <= _ && _ <= R)
          return !0;
      }
      return !1;
    }
  };
}
const Kp = /* @__PURE__ */ xi({
  name: "FontResolver",
  dependencies: [
    Zp,
    Yp,
    jp
  ],
  init(a, e, t) {
    return a(e, t());
  }
});
function Jp(a, e) {
  const r = /[\u00AD\u034F\u061C\u115F-\u1160\u17B4-\u17B5\u180B-\u180E\u200B-\u200F\u202A-\u202E\u2060-\u206F\u3164\uFE00-\uFE0F\uFEFF\uFFA0\uFFF0-\uFFF8]/, n = "[^\\S\\u00A0]", i = new RegExp(`${n}|[\\-\\u007C\\u00AD\\u2010\\u2012-\\u2014\\u2027\\u2056\\u2E17\\u2E40]`);
  function s({ text: g, lang: v, fonts: m, style: p, weight: T, preResolvedFonts: x, unicodeFontsURL: _ }, D) {
    const C = ({ chars: A, fonts: R }) => {
      let E, S;
      const F = [];
      for (let L = 0; L < A.length; L++)
        A[L] !== S ? (S = A[L], F.push(E = { start: L, end: L, fontObj: R[A[L]] })) : E.end = L;
      D(F);
    };
    x ? C(x) : a(
      g,
      C,
      { lang: v, fonts: m, style: p, weight: T, unicodeFontsURL: _ }
    );
  }
  function o({
    text: g = "",
    font: v,
    lang: m,
    sdfGlyphSize: p = 64,
    fontSize: T = 400,
    fontWeight: x = 1,
    fontStyle: _ = "normal",
    letterSpacing: D = 0,
    lineHeight: C = "normal",
    maxWidth: A = 1 / 0,
    direction: R,
    textAlign: E = "left",
    textIndent: S = 0,
    whiteSpace: F = "normal",
    overflowWrap: L = "normal",
    anchorX: B = 0,
    anchorY: k = 0,
    metricsOnly: O = !1,
    unicodeFontsURL: z,
    preResolvedFonts: ne = null,
    includeCaretPositions: q = !1,
    chunkedBoundsSize: K = 8192,
    colorRanges: Z = null
  }, N) {
    const Y = f(), ie = { fontLoad: 0, typesetting: 0 };
    g.indexOf("\r") > -1 && (console.info("Typesetter: got text with \\r chars; normalizing to \\n"), g = g.replace(/\r\n/g, `
`).replace(/\r/g, `
`)), T = +T, D = +D, A = +A, C = C || "normal", S = +S, s({
      text: g,
      lang: m,
      style: _,
      weight: x,
      fonts: typeof v == "string" ? [{ src: v }] : v,
      unicodeFontsURL: z,
      preResolvedFonts: ne
    }, (b) => {
      ie.fontLoad = f() - Y;
      const U = isFinite(A);
      let G = null, I = null, V = null, re = null, he = null, fe = null, W = null, ce = null, P = 0, pe = 0, ae = F !== "nowrap";
      const ve = /* @__PURE__ */ new Map(), te = f();
      let Te = S, me = 0, M = new h();
      const y = [M];
      b.forEach((Se) => {
        const { fontObj: de } = Se, { ascender: xe, descender: De, unitsPerEm: ye, lineGap: Re, capHeight: Pe, xHeight: Ue } = de;
        let Me = ve.get(de);
        if (!Me) {
          const _e = T / ye, se = C === "normal" ? (xe - De + Re) * _e : C * T, Ee = (se - (xe - De) * _e) / 2, Ae = Math.min(se, (xe - De) * _e), be = (xe + De) / 2 * _e + Ae / 2;
          Me = {
            index: ve.size,
            src: de.src,
            fontObj: de,
            fontSizeMult: _e,
            unitsPerEm: ye,
            ascender: xe * _e,
            descender: De * _e,
            capHeight: Pe * _e,
            xHeight: Ue * _e,
            lineHeight: se,
            baseline: -Ee - xe * _e,
            // baseline offset from top of line height
            // cap: -halfLeading - capHeight * fontSizeMult, // cap from top of line height
            // ex: -halfLeading - xHeight * fontSizeMult, // ex from top of line height
            caretTop: be,
            caretBottom: be - Ae
          }, ve.set(de, Me);
        }
        const { fontSizeMult: ze } = Me, Fe = g.slice(Se.start, Se.end + 1);
        let je, X;
        de.forEachGlyph(Fe, T, D, (_e, se, Ee, Ae) => {
          se += me, Ae += Se.start, je = se, X = _e;
          const be = g.charAt(Ae), Ne = _e.advanceWidth * ze, We = M.count;
          let Ge;
          if ("isEmpty" in _e || (_e.isWhitespace = !!be && new RegExp(n).test(be), _e.canBreakAfter = !!be && i.test(be), _e.isEmpty = _e.xMin === _e.xMax || _e.yMin === _e.yMax || r.test(be)), !_e.isWhitespace && !_e.isEmpty && pe++, ae && U && !_e.isWhitespace && se + Ne + Te > A && We) {
            if (M.glyphAt(We - 1).glyphObj.canBreakAfter)
              Ge = new h(), Te = -se;
            else
              for (let rt = We; rt--; )
                if (rt === 0 && L === "break-word") {
                  Ge = new h(), Te = -se;
                  break;
                } else if (M.glyphAt(rt).glyphObj.canBreakAfter) {
                  Ge = M.splitAt(rt + 1);
                  const at = Ge.glyphAt(0).x;
                  Te -= at;
                  for (let ct = Ge.count; ct--; )
                    Ge.glyphAt(ct).x -= at;
                  break;
                }
            Ge && (M.isSoftWrapped = !0, M = Ge, y.push(M), P = A);
          }
          let Ve = M.glyphAt(M.count);
          Ve.glyphObj = _e, Ve.x = se + Te, Ve.y = Ee, Ve.width = Ne, Ve.charIndex = Ae, Ve.fontData = Me, be === `
` && (M = new h(), y.push(M), Te = -(se + Ne + D * T) + S);
        }), me = je + X.advanceWidth * ze + D * T;
      });
      let H = 0;
      y.forEach((Se) => {
        let de = !0;
        for (let xe = Se.count; xe--; ) {
          const De = Se.glyphAt(xe);
          de && !De.glyphObj.isWhitespace && (Se.width = De.x + De.width, Se.width > P && (P = Se.width), de = !1);
          let { lineHeight: ye, capHeight: Re, xHeight: Pe, baseline: Ue } = De.fontData;
          ye > Se.lineHeight && (Se.lineHeight = ye);
          const Me = Ue - Se.baseline;
          Me < 0 && (Se.baseline += Me, Se.cap += Me, Se.ex += Me), Se.cap = Math.max(Se.cap, Se.baseline + Re), Se.ex = Math.max(Se.ex, Se.baseline + Pe);
        }
        Se.baseline -= H, Se.cap -= H, Se.ex -= H, H += Se.lineHeight;
      });
      let $ = 0, ee = 0;
      if (B && (typeof B == "number" ? $ = -B : typeof B == "string" && ($ = -P * (B === "left" ? 0 : B === "center" ? 0.5 : B === "right" ? 1 : c(B)))), k && (typeof k == "number" ? ee = -k : typeof k == "string" && (ee = k === "top" ? 0 : k === "top-baseline" ? -y[0].baseline : k === "top-cap" ? -y[0].cap : k === "top-ex" ? -y[0].ex : k === "middle" ? H / 2 : k === "bottom" ? H : k === "bottom-baseline" ? -y[y.length - 1].baseline : c(k) * H)), !O) {
        const Se = e.getEmbeddingLevels(g, R);
        G = new Uint16Array(pe), I = new Uint8Array(pe), V = new Float32Array(pe * 2), re = {}, W = [1 / 0, 1 / 0, -1 / 0, -1 / 0], ce = [], q && (fe = new Float32Array(g.length * 4)), Z && (he = new Uint8Array(pe * 3));
        let de = 0, xe = -1, De = -1, ye, Re;
        if (y.forEach((Pe, Ue) => {
          let { count: Me, width: ze } = Pe;
          if (Me > 0) {
            let Fe = 0;
            for (let Ae = Me; Ae-- && Pe.glyphAt(Ae).glyphObj.isWhitespace; )
              Fe++;
            let je = 0, X = 0;
            if (E === "center")
              je = (P - ze) / 2;
            else if (E === "right")
              je = P - ze;
            else if (E === "justify" && Pe.isSoftWrapped) {
              let Ae = 0;
              for (let be = Me - Fe; be--; )
                Pe.glyphAt(be).glyphObj.isWhitespace && Ae++;
              X = (P - ze) / Ae;
            }
            if (X || je) {
              let Ae = 0;
              for (let be = 0; be < Me; be++) {
                let Ne = Pe.glyphAt(be);
                const We = Ne.glyphObj;
                Ne.x += je + Ae, X !== 0 && We.isWhitespace && be < Me - Fe && (Ae += X, Ne.width += X);
              }
            }
            const _e = e.getReorderSegments(
              g,
              Se,
              Pe.glyphAt(0).charIndex,
              Pe.glyphAt(Pe.count - 1).charIndex
            );
            for (let Ae = 0; Ae < _e.length; Ae++) {
              const [be, Ne] = _e[Ae];
              let We = 1 / 0, Ge = -1 / 0;
              for (let Ve = 0; Ve < Me; Ve++)
                if (Pe.glyphAt(Ve).charIndex >= be) {
                  let rt = Ve, at = Ve;
                  for (; at < Me; at++) {
                    let ct = Pe.glyphAt(at);
                    if (ct.charIndex > Ne)
                      break;
                    at < Me - Fe && (We = Math.min(We, ct.x), Ge = Math.max(Ge, ct.x + ct.width));
                  }
                  for (let ct = rt; ct < at; ct++) {
                    const Ct = Pe.glyphAt(ct);
                    Ct.x = Ge - (Ct.x + Ct.width - We);
                  }
                  break;
                }
            }
            let se;
            const Ee = (Ae) => se = Ae;
            for (let Ae = 0; Ae < Me; Ae++) {
              const be = Pe.glyphAt(Ae);
              se = be.glyphObj;
              const Ne = se.index, We = Se.levels[be.charIndex] & 1;
              if (We) {
                const Ge = e.getMirroredCharacter(g[be.charIndex]);
                Ge && be.fontData.fontObj.forEachGlyph(Ge, 0, 0, Ee);
              }
              if (q) {
                const { charIndex: Ge, fontData: Ve } = be, rt = be.x + $, at = be.x + be.width + $;
                fe[Ge * 4] = We ? at : rt, fe[Ge * 4 + 1] = We ? rt : at, fe[Ge * 4 + 2] = Pe.baseline + Ve.caretBottom + ee, fe[Ge * 4 + 3] = Pe.baseline + Ve.caretTop + ee;
                const ct = Ge - xe;
                ct > 1 && u(fe, xe, ct), xe = Ge;
              }
              if (Z) {
                const { charIndex: Ge } = be;
                for (; Ge > De; )
                  De++, Z.hasOwnProperty(De) && (Re = Z[De]);
              }
              if (!se.isWhitespace && !se.isEmpty) {
                const Ge = de++, { fontSizeMult: Ve, src: rt, index: at } = be.fontData, ct = re[rt] || (re[rt] = {});
                ct[Ne] || (ct[Ne] = {
                  path: se.path,
                  pathBounds: [se.xMin, se.yMin, se.xMax, se.yMax]
                });
                const Ct = be.x + $, yt = be.y + Pe.baseline + ee;
                V[Ge * 2] = Ct, V[Ge * 2 + 1] = yt;
                const Ot = Ct + se.xMin * Ve, qt = yt + se.yMin * Ve, nn = Ct + se.xMax * Ve, Rt = yt + se.yMax * Ve;
                Ot < W[0] && (W[0] = Ot), qt < W[1] && (W[1] = qt), nn > W[2] && (W[2] = nn), Rt > W[3] && (W[3] = Rt), Ge % K === 0 && (ye = { start: Ge, end: Ge, rect: [1 / 0, 1 / 0, -1 / 0, -1 / 0] }, ce.push(ye)), ye.end++;
                const pt = ye.rect;
                if (Ot < pt[0] && (pt[0] = Ot), qt < pt[1] && (pt[1] = qt), nn > pt[2] && (pt[2] = nn), Rt > pt[3] && (pt[3] = Rt), G[Ge] = Ne, I[Ge] = at, Z) {
                  const Ht = Ge * 3;
                  he[Ht] = Re >> 16 & 255, he[Ht + 1] = Re >> 8 & 255, he[Ht + 2] = Re & 255;
                }
              }
            }
          }
        }), fe) {
          const Pe = g.length - xe;
          Pe > 1 && u(fe, xe, Pe);
        }
      }
      const oe = [];
      ve.forEach(({ index: Se, src: de, unitsPerEm: xe, ascender: De, descender: ye, lineHeight: Re, capHeight: Pe, xHeight: Ue }) => {
        oe[Se] = { src: de, unitsPerEm: xe, ascender: De, descender: ye, lineHeight: Re, capHeight: Pe, xHeight: Ue };
      }), ie.typesetting = f() - te, N({
        glyphIds: G,
        //id for each glyph, specific to that glyph's font
        glyphFontIndices: I,
        //index into fontData for each glyph
        glyphPositions: V,
        //x,y of each glyph's origin in layout
        glyphData: re,
        //dict holding data about each glyph appearing in the text
        fontData: oe,
        //data about each font used in the text
        caretPositions: fe,
        //startX,endX,bottomY caret positions for each char
        // caretHeight, //height of cursor from bottom to top - todo per glyph?
        glyphColors: he,
        //color for each glyph, if color ranges supplied
        chunkedBounds: ce,
        //total rects per (n=chunkedBoundsSize) consecutive glyphs
        fontSize: T,
        //calculated em height
        topBaseline: ee + y[0].baseline,
        //y coordinate of the top line's baseline
        blockBounds: [
          //bounds for the whole block of text, including vertical padding for lineHeight
          $,
          ee - H,
          $ + P,
          ee
        ],
        visibleBounds: W,
        //total bounds of visible text paths, may be larger or smaller than blockBounds
        timings: ie
      });
    });
  }
  function l(g, v) {
    o({ ...g, metricsOnly: !0 }, (m) => {
      const [p, T, x, _] = m.blockBounds;
      v({
        width: x - p,
        height: _ - T
      });
    });
  }
  function c(g) {
    let v = g.match(/^([\d.]+)%$/), m = v ? parseFloat(v[1]) : NaN;
    return isNaN(m) ? 0 : m / 100;
  }
  function u(g, v, m) {
    const p = g[v * 4], T = g[v * 4 + 1], x = g[v * 4 + 2], _ = g[v * 4 + 3], D = (T - p) / m;
    for (let C = 0; C < m; C++) {
      const A = (v + C) * 4;
      g[A] = p + D * C, g[A + 1] = p + D * (C + 1), g[A + 2] = x, g[A + 3] = _;
    }
  }
  function f() {
    return (self.performance || Date).now();
  }
  function h() {
    this.data = [];
  }
  const d = ["glyphObj", "x", "y", "width", "charIndex", "fontData"];
  return h.prototype = {
    width: 0,
    lineHeight: 0,
    baseline: 0,
    cap: 0,
    ex: 0,
    isSoftWrapped: !1,
    get count() {
      return Math.ceil(this.data.length / d.length);
    },
    glyphAt(g) {
      let v = h.flyweight;
      return v.data = this.data, v.index = g, v;
    },
    splitAt(g) {
      let v = new h();
      return v.data = this.data.splice(g * d.length), v;
    }
  }, h.flyweight = d.reduce((g, v, m, p) => (Object.defineProperty(g, v, {
    get() {
      return this.data[this.index * d.length + m];
    },
    set(T) {
      this.data[this.index * d.length + m] = T;
    }
  }), g), { data: null, index: 0 }), {
    typeset: o,
    measure: l
  };
}
const On = () => (self.performance || Date).now(), Hr = /* @__PURE__ */ fl();
let bo;
function Qp(a, e, t, r, n, i, s, o, l, c, u = !0) {
  return u ? em(a, e, t, r, n, i, s, o, l, c).then(
    null,
    (f) => (bo || (console.warn("WebGL SDF generation failed, falling back to JS", f), bo = !0), wo(a, e, t, r, n, i, s, o, l, c))
  ) : wo(a, e, t, r, n, i, s, o, l, c);
}
const Ir = [], $p = 5;
let Za = 0;
function pl() {
  const a = On();
  for (; Ir.length && On() - a < $p; )
    Ir.shift()();
  Za = Ir.length ? setTimeout(pl, 0) : 0;
}
const em = (...a) => new Promise((e, t) => {
  Ir.push(() => {
    const r = On();
    try {
      Hr.webgl.generateIntoCanvas(...a), e({ timing: On() - r });
    } catch (n) {
      t(n);
    }
  }), Za || (Za = setTimeout(pl, 0));
}), tm = 4, nm = 2e3, Ao = {};
let im = 0;
function wo(a, e, t, r, n, i, s, o, l, c) {
  const u = "TroikaTextSDFGenerator_JS_" + im++ % tm;
  let f = Ao[u];
  return f || (f = Ao[u] = {
    workerModule: xi({
      name: u,
      workerId: u,
      dependencies: [
        fl,
        On
      ],
      init(h, d) {
        const g = h().javascript.generate;
        return function(...v) {
          const m = d();
          return {
            textureData: g(...v),
            timing: d() - m
          };
        };
      },
      getTransferables(h) {
        return [h.textureData.buffer];
      }
    }),
    requests: 0,
    idleTimer: null
  }), f.requests++, clearTimeout(f.idleTimer), f.workerModule(a, e, t, r, n, i).then(({ textureData: h, timing: d }) => {
    const g = On(), v = new Uint8Array(h.length * 4);
    for (let m = 0; m < h.length; m++)
      v[m * 4 + c] = h[m];
    return Hr.webglUtils.renderImageData(s, v, o, l, a, e, 1 << 3 - c), d += On() - g, --f.requests === 0 && (f.idleTimer = setTimeout(() => {
      Fp(u);
    }, nm)), { timing: d };
  });
}
function rm(a) {
  a._warm || (Hr.webgl.isSupported(a), a._warm = !0);
}
const am = Hr.webglUtils.resizeWebGLCanvasWithoutClearing, si = {
  defaultFontURL: null,
  unicodeFontsURL: null,
  sdfGlyphSize: 64,
  sdfMargin: 1 / 16,
  sdfExponent: 9,
  textureWidth: 2048
}, sm = /* @__PURE__ */ new Ke();
function ai() {
  return (self.performance || Date).now();
}
const Co = /* @__PURE__ */ Object.create(null);
function om(a, e) {
  a = cm({}, a);
  const t = ai(), { defaultFontURL: r } = si, n = [];
  if (r && n.push({ label: "default", src: Ro(r) }), a.font && n.push({ label: "user", src: Ro(a.font) }), a.font = n, a.text = "" + a.text, a.sdfGlyphSize = a.sdfGlyphSize || si.sdfGlyphSize, a.unicodeFontsURL = a.unicodeFontsURL || si.unicodeFontsURL, a.colorRanges != null) {
    let h = {};
    for (let d in a.colorRanges)
      if (a.colorRanges.hasOwnProperty(d)) {
        let g = a.colorRanges[d];
        typeof g != "number" && (g = sm.set(g).getHex()), h[d] = g;
      }
    a.colorRanges = h;
  }
  Object.freeze(a);
  const { textureWidth: i, sdfExponent: s } = si, { sdfGlyphSize: o } = a, l = i / o * 4;
  let c = Co[o];
  if (!c) {
    const h = document.createElement("canvas");
    h.width = i, h.height = o * 256 / l, c = Co[o] = {
      glyphCount: 0,
      sdfGlyphSize: o,
      sdfCanvas: h,
      sdfTexture: new wt(
        h,
        void 0,
        void 0,
        void 0,
        1006,
        1006
      ),
      contextLost: !1,
      glyphsByFont: /* @__PURE__ */ new Map()
    }, c.sdfTexture.generateMipmaps = !1, lm(c);
  }
  const { sdfTexture: u, sdfCanvas: f } = c;
  hm(a).then((h) => {
    const { glyphIds: d, glyphFontIndices: g, fontData: v, glyphPositions: m, fontSize: p, timings: T } = h, x = [], _ = new Float32Array(d.length * 4);
    let D = 0, C = 0;
    const A = ai(), R = v.map((B) => {
      let k = c.glyphsByFont.get(B.src);
      return k || c.glyphsByFont.set(B.src, k = /* @__PURE__ */ new Map()), k;
    });
    d.forEach((B, k) => {
      const O = g[k], { src: z, unitsPerEm: ne } = v[O];
      let q = R[O].get(B);
      if (!q) {
        const { path: ie, pathBounds: b } = h.glyphData[z][B], U = Math.max(b[2] - b[0], b[3] - b[1]) / o * (si.sdfMargin * o + 0.5), G = c.glyphCount++, I = [
          b[0] - U,
          b[1] - U,
          b[2] + U,
          b[3] + U
        ];
        R[O].set(B, q = { path: ie, atlasIndex: G, sdfViewBox: I }), x.push(q);
      }
      const { sdfViewBox: K } = q, Z = m[C++], N = m[C++], Y = p / ne;
      _[D++] = Z + K[0] * Y, _[D++] = N + K[1] * Y, _[D++] = Z + K[2] * Y, _[D++] = N + K[3] * Y, d[k] = q.atlasIndex;
    }), T.quads = (T.quads || 0) + (ai() - A);
    const E = ai();
    T.sdf = {};
    const S = f.height, F = Math.ceil(c.glyphCount / l), L = Math.pow(2, Math.ceil(Math.log2(F * o)));
    L > S && (console.info(`Increasing SDF texture size ${S}->${L}`), am(f, i, L), u.dispose()), Promise.all(x.map(
      (B) => ml(B, c, a.gpuAccelerateSDF).then(({ timing: k }) => {
        T.sdf[B.atlasIndex] = k;
      })
    )).then(() => {
      x.length && !c.contextLost && (gl(c), u.needsUpdate = !0), T.sdfTotal = ai() - E, T.total = ai() - t, e(Object.freeze({
        parameters: a,
        sdfTexture: u,
        sdfGlyphSize: o,
        sdfExponent: s,
        glyphBounds: _,
        glyphAtlasIndices: d,
        glyphColors: h.glyphColors,
        caretPositions: h.caretPositions,
        chunkedBounds: h.chunkedBounds,
        ascender: h.ascender,
        descender: h.descender,
        lineHeight: h.lineHeight,
        capHeight: h.capHeight,
        xHeight: h.xHeight,
        topBaseline: h.topBaseline,
        blockBounds: h.blockBounds,
        visibleBounds: h.visibleBounds,
        timings: h.timings
      }));
    });
  }), Promise.resolve().then(() => {
    c.contextLost || rm(f);
  });
}
function ml({ path: a, atlasIndex: e, sdfViewBox: t }, { sdfGlyphSize: r, sdfCanvas: n, contextLost: i }, s) {
  if (i)
    return Promise.resolve({ timing: -1 });
  const { textureWidth: o, sdfExponent: l } = si, c = Math.max(t[2] - t[0], t[3] - t[1]), u = Math.floor(e / 4), f = u % (o / r) * r, h = Math.floor(u / (o / r)) * r, d = e % 4;
  return Qp(r, r, a, t, c, l, n, f, h, d, s);
}
function lm(a) {
  const e = a.sdfCanvas;
  e.addEventListener("webglcontextlost", (t) => {
    console.log("Context Lost", t), t.preventDefault(), a.contextLost = !0;
  }), e.addEventListener("webglcontextrestored", (t) => {
    console.log("Context Restored", t), a.contextLost = !1;
    const r = [];
    a.glyphsByFont.forEach((n) => {
      n.forEach((i) => {
        r.push(ml(i, a, !0));
      });
    }), Promise.all(r).then(() => {
      gl(a), a.sdfTexture.needsUpdate = !0;
    });
  });
}
function cm(a, e) {
  for (let t in e)
    e.hasOwnProperty(t) && (a[t] = e[t]);
  return a;
}
let Pr;
function Ro(a) {
  return Pr || (Pr = typeof document > "u" ? {} : document.createElement("a")), Pr.href = a, Pr.href;
}
function gl(a) {
  if (typeof createImageBitmap != "function") {
    console.info("Safari<15: applying SDF canvas workaround");
    const { sdfCanvas: e, sdfTexture: t } = a, { width: r, height: n } = e, i = a.sdfCanvas.getContext("webgl");
    let s = t.image.data;
    (!s || s.length !== r * n * 4) && (s = new Uint8Array(r * n * 4), t.image = { width: r, height: n, data: s }, t.flipY = !1, t.isDataTexture = !0), i.readPixels(0, 0, r, n, i.RGBA, i.UNSIGNED_BYTE, s);
  }
}
const um = /* @__PURE__ */ xi({
  name: "Typesetter",
  dependencies: [
    Jp,
    Kp,
    Np
  ],
  init(a, e, t) {
    return a(e, t());
  }
}), hm = /* @__PURE__ */ xi({
  name: "Typesetter",
  dependencies: [
    um
  ],
  init(a) {
    return function(e) {
      return new Promise((t) => {
        a.typeset(e, t);
      });
    };
  },
  getTransferables(a) {
    const e = [];
    for (let t in a)
      a[t] && a[t].buffer && e.push(a[t].buffer);
    return e;
  }
}), Po = {};
function fm(a) {
  let e = Po[a];
  return e || (e = Po[a] = new zn(1, 1, a, a).translate(0.5, 0.5, 0)), e;
}
const dm = "aTroikaGlyphBounds", Uo = "aTroikaGlyphIndex", pm = "aTroikaGlyphColor";
class mm extends yp {
  constructor() {
    super(), this.detail = 1, this.curveRadius = 0, this.groups = [
      { start: 0, count: 1 / 0, materialIndex: 0 },
      { start: 0, count: 1 / 0, materialIndex: 1 }
    ], this.boundingSphere = new gi(), this.boundingBox = new An();
  }
  computeBoundingSphere() {
  }
  computeBoundingBox() {
  }
  set detail(e) {
    if (e !== this._detail) {
      this._detail = e, (typeof e != "number" || e < 1) && (e = 1);
      let t = fm(e);
      ["position", "normal", "uv"].forEach((r) => {
        this.attributes[r] = t.attributes[r].clone();
      }), this.setIndex(t.getIndex().clone());
    }
  }
  get detail() {
    return this._detail;
  }
  set curveRadius(e) {
    e !== this._curveRadius && (this._curveRadius = e, this._updateBounds());
  }
  get curveRadius() {
    return this._curveRadius;
  }
  /**
   * Update the geometry for a new set of glyphs.
   * @param {Float32Array} glyphBounds - An array holding the planar bounds for all glyphs
   *        to be rendered, 4 entries for each glyph: x1,x2,y1,y1
   * @param {Float32Array} glyphAtlasIndices - An array holding the index of each glyph within
   *        the SDF atlas texture.
   * @param {Array} blockBounds - An array holding the [minX, minY, maxX, maxY] across all glyphs
   * @param {Array} [chunkedBounds] - An array of objects describing bounds for each chunk of N
   *        consecutive glyphs: `{start:N, end:N, rect:[minX, minY, maxX, maxY]}`. This can be
   *        used with `applyClipRect` to choose an optimized `instanceCount`.
   * @param {Uint8Array} [glyphColors] - An array holding r,g,b values for each glyph.
   */
  updateGlyphs(e, t, r, n, i) {
    this.updateAttributeData(dm, e, 4), this.updateAttributeData(Uo, t, 1), this.updateAttributeData(pm, i, 3), this._blockBounds = r, this._chunkedBounds = n, this.instanceCount = t.length, this._updateBounds();
  }
  _updateBounds() {
    const e = this._blockBounds;
    if (e) {
      const { curveRadius: t, boundingBox: r } = this;
      if (t) {
        const { PI: n, floor: i, min: s, max: o, sin: l, cos: c } = Math, u = n / 2, f = n * 2, h = Math.abs(t), d = e[0] / h, g = e[2] / h, v = i((d + u) / f) !== i((g + u) / f) ? -h : s(l(d) * h, l(g) * h), m = i((d - u) / f) !== i((g - u) / f) ? h : o(l(d) * h, l(g) * h), p = i((d + n) / f) !== i((g + n) / f) ? h * 2 : o(h - c(d) * h, h - c(g) * h);
        r.min.set(v, e[1], t < 0 ? -p : 0), r.max.set(m, e[3], t < 0 ? 0 : p);
      } else
        r.min.set(e[0], e[1], 0), r.max.set(e[2], e[3], 0);
      r.getBoundingSphere(this.boundingSphere);
    }
  }
  /**
   * Given a clipping rect, and the chunkedBounds from the last updateGlyphs call, choose the lowest
   * `instanceCount` that will show all glyphs within the clipped view. This is an optimization
   * for long blocks of text that are clipped, to skip vertex shader evaluation for glyphs that would
   * be clipped anyway.
   *
   * Note that since `drawElementsInstanced[ANGLE]` only accepts an instance count and not a starting
   * offset, this optimization becomes less effective as the clipRect moves closer to the end of the
   * text block. We could fix that by switching from instancing to a full geometry with a drawRange,
   * but at the expense of much larger attribute buffers (see classdoc above.)
   *
   * @param {Vector4} clipRect
   */
  applyClipRect(e) {
    let t = this.getAttribute(Uo).count, r = this._chunkedBounds;
    if (r)
      for (let n = r.length; n--; ) {
        t = r[n].end;
        let i = r[n].rect;
        if (i[1] < e.w && i[3] > e.y && i[0] < e.z && i[2] > e.x)
          break;
      }
    this.instanceCount = t;
  }
  /**
   * Utility for updating instance attributes with automatic resizing
   */
  updateAttributeData(e, t, r) {
    const n = this.getAttribute(e);
    t ? n && n.array.length === t.length ? (n.array.set(t), n.needsUpdate = !0) : (this.setAttribute(e, new Od(t, r)), delete this._maxInstanceCount, this.dispose()) : n && this.deleteAttribute(e);
  }
}
const gm = `
uniform vec2 uTroikaSDFTextureSize;
uniform float uTroikaSDFGlyphSize;
uniform vec4 uTroikaTotalBounds;
uniform vec4 uTroikaClipRect;
uniform mat3 uTroikaOrient;
uniform bool uTroikaUseGlyphColors;
uniform float uTroikaDistanceOffset;
uniform float uTroikaBlurRadius;
uniform vec2 uTroikaPositionOffset;
uniform float uTroikaCurveRadius;
attribute vec4 aTroikaGlyphBounds;
attribute float aTroikaGlyphIndex;
attribute vec3 aTroikaGlyphColor;
varying vec2 vTroikaGlyphUV;
varying vec4 vTroikaTextureUVBounds;
varying float vTroikaTextureChannel;
varying vec3 vTroikaGlyphColor;
varying vec2 vTroikaGlyphDimensions;
`, vm = `
vec4 bounds = aTroikaGlyphBounds;
bounds.xz += uTroikaPositionOffset.x;
bounds.yw -= uTroikaPositionOffset.y;

vec4 outlineBounds = vec4(
  bounds.xy - uTroikaDistanceOffset - uTroikaBlurRadius,
  bounds.zw + uTroikaDistanceOffset + uTroikaBlurRadius
);
vec4 clippedBounds = vec4(
  clamp(outlineBounds.xy, uTroikaClipRect.xy, uTroikaClipRect.zw),
  clamp(outlineBounds.zw, uTroikaClipRect.xy, uTroikaClipRect.zw)
);

vec2 clippedXY = (mix(clippedBounds.xy, clippedBounds.zw, position.xy) - bounds.xy) / (bounds.zw - bounds.xy);

position.xy = mix(bounds.xy, bounds.zw, clippedXY);

uv = (position.xy - uTroikaTotalBounds.xy) / (uTroikaTotalBounds.zw - uTroikaTotalBounds.xy);

float rad = uTroikaCurveRadius;
if (rad != 0.0) {
  float angle = position.x / rad;
  position.xz = vec2(sin(angle) * rad, rad - cos(angle) * rad);
  normal.xz = vec2(sin(angle), cos(angle));
}
  
position = uTroikaOrient * position;
normal = uTroikaOrient * normal;

vTroikaGlyphUV = clippedXY.xy;
vTroikaGlyphDimensions = vec2(bounds[2] - bounds[0], bounds[3] - bounds[1]);


float txCols = uTroikaSDFTextureSize.x / uTroikaSDFGlyphSize;
vec2 txUvPerSquare = uTroikaSDFGlyphSize / uTroikaSDFTextureSize;
vec2 txStartUV = txUvPerSquare * vec2(
  mod(floor(aTroikaGlyphIndex / 4.0), txCols),
  floor(floor(aTroikaGlyphIndex / 4.0) / txCols)
);
vTroikaTextureUVBounds = vec4(txStartUV, vec2(txStartUV) + txUvPerSquare);
vTroikaTextureChannel = mod(aTroikaGlyphIndex, 4.0);
`, _m = `
uniform sampler2D uTroikaSDFTexture;
uniform vec2 uTroikaSDFTextureSize;
uniform float uTroikaSDFGlyphSize;
uniform float uTroikaSDFExponent;
uniform float uTroikaDistanceOffset;
uniform float uTroikaFillOpacity;
uniform float uTroikaOutlineOpacity;
uniform float uTroikaBlurRadius;
uniform vec3 uTroikaStrokeColor;
uniform float uTroikaStrokeWidth;
uniform float uTroikaStrokeOpacity;
uniform bool uTroikaSDFDebug;
varying vec2 vTroikaGlyphUV;
varying vec4 vTroikaTextureUVBounds;
varying float vTroikaTextureChannel;
varying vec2 vTroikaGlyphDimensions;

float troikaSdfValueToSignedDistance(float alpha) {
  // Inverse of exponential encoding in webgl-sdf-generator
  
  float maxDimension = max(vTroikaGlyphDimensions.x, vTroikaGlyphDimensions.y);
  float absDist = (1.0 - pow(2.0 * (alpha > 0.5 ? 1.0 - alpha : alpha), 1.0 / uTroikaSDFExponent)) * maxDimension;
  float signedDist = absDist * (alpha > 0.5 ? -1.0 : 1.0);
  return signedDist;
}

float troikaGlyphUvToSdfValue(vec2 glyphUV) {
  vec2 textureUV = mix(vTroikaTextureUVBounds.xy, vTroikaTextureUVBounds.zw, glyphUV);
  vec4 rgba = texture2D(uTroikaSDFTexture, textureUV);
  float ch = floor(vTroikaTextureChannel + 0.5); //NOTE: can't use round() in WebGL1
  return ch == 0.0 ? rgba.r : ch == 1.0 ? rgba.g : ch == 2.0 ? rgba.b : rgba.a;
}

float troikaGlyphUvToDistance(vec2 uv) {
  return troikaSdfValueToSignedDistance(troikaGlyphUvToSdfValue(uv));
}

float troikaGetAADist() {
  
  #if defined(GL_OES_standard_derivatives) || __VERSION__ >= 300
  return length(fwidth(vTroikaGlyphUV * vTroikaGlyphDimensions)) * 0.5;
  #else
  return vTroikaGlyphDimensions.x / 64.0;
  #endif
}

float troikaGetFragDistValue() {
  vec2 clampedGlyphUV = clamp(vTroikaGlyphUV, 0.5 / uTroikaSDFGlyphSize, 1.0 - 0.5 / uTroikaSDFGlyphSize);
  float distance = troikaGlyphUvToDistance(clampedGlyphUV);
 
  // Extrapolate distance when outside bounds:
  distance += clampedGlyphUV == vTroikaGlyphUV ? 0.0 : 
    length((vTroikaGlyphUV - clampedGlyphUV) * vTroikaGlyphDimensions);

  

  return distance;
}

float troikaGetEdgeAlpha(float distance, float distanceOffset, float aaDist) {
  #if defined(IS_DEPTH_MATERIAL) || defined(IS_DISTANCE_MATERIAL)
  float alpha = step(-distanceOffset, -distance);
  #else

  float alpha = smoothstep(
    distanceOffset + aaDist,
    distanceOffset - aaDist,
    distance
  );
  #endif

  return alpha;
}
`, xm = `
float aaDist = troikaGetAADist();
float fragDistance = troikaGetFragDistValue();
float edgeAlpha = uTroikaSDFDebug ?
  troikaGlyphUvToSdfValue(vTroikaGlyphUV) :
  troikaGetEdgeAlpha(fragDistance, uTroikaDistanceOffset, max(aaDist, uTroikaBlurRadius));

#if !defined(IS_DEPTH_MATERIAL) && !defined(IS_DISTANCE_MATERIAL)
vec4 fillRGBA = gl_FragColor;
fillRGBA.a *= uTroikaFillOpacity;
vec4 strokeRGBA = uTroikaStrokeWidth == 0.0 ? fillRGBA : vec4(uTroikaStrokeColor, uTroikaStrokeOpacity);
if (fillRGBA.a == 0.0) fillRGBA.rgb = strokeRGBA.rgb;
gl_FragColor = mix(fillRGBA, strokeRGBA, smoothstep(
  -uTroikaStrokeWidth - aaDist,
  -uTroikaStrokeWidth + aaDist,
  fragDistance
));
gl_FragColor.a *= edgeAlpha;
#endif

if (edgeAlpha == 0.0) {
  discard;
}
`;
function Sm(a) {
  const e = ja(a, {
    chained: !0,
    extensions: {
      derivatives: !0
    },
    uniforms: {
      uTroikaSDFTexture: { value: null },
      uTroikaSDFTextureSize: { value: new Ce() },
      uTroikaSDFGlyphSize: { value: 0 },
      uTroikaSDFExponent: { value: 0 },
      uTroikaTotalBounds: { value: new ot(0, 0, 0, 0) },
      uTroikaClipRect: { value: new ot(0, 0, 0, 0) },
      uTroikaDistanceOffset: { value: 0 },
      uTroikaOutlineOpacity: { value: 0 },
      uTroikaFillOpacity: { value: 1 },
      uTroikaPositionOffset: { value: new Ce() },
      uTroikaCurveRadius: { value: 0 },
      uTroikaBlurRadius: { value: 0 },
      uTroikaStrokeWidth: { value: 0 },
      uTroikaStrokeColor: { value: new Ke() },
      uTroikaStrokeOpacity: { value: 1 },
      uTroikaOrient: { value: new Ye() },
      uTroikaUseGlyphColors: { value: !0 },
      uTroikaSDFDebug: { value: !1 }
    },
    vertexDefs: gm,
    vertexTransform: vm,
    fragmentDefs: _m,
    fragmentColorTransform: xm,
    customRewriter({ vertexShader: t, fragmentShader: r }) {
      let n = /\buniform\s+vec3\s+diffuse\b/;
      return n.test(r) && (r = r.replace(n, "varying vec3 vTroikaGlyphColor").replace(/\bdiffuse\b/g, "vTroikaGlyphColor"), n.test(t) || (t = t.replace(
        dl,
        `uniform vec3 diffuse;
$&
vTroikaGlyphColor = uTroikaUseGlyphColors ? aTroikaGlyphColor / 255.0 : diffuse;
`
      ))), { vertexShader: t, fragmentShader: r };
    }
  });
  return e.transparent = !0, e.forceSinglePass = !0, Object.defineProperties(e, {
    isTroikaTextMaterial: { value: !0 },
    // WebGLShadowMap reverses the side of the shadow material by default, which fails
    // for planes, so here we force the `shadowSide` to always match the main side.
    shadowSide: {
      get() {
        return this.side;
      },
      set() {
      }
    }
  }), e;
}
const is = /* @__PURE__ */ new Vi({
  color: 16777215,
  side: 2,
  transparent: !0
}), Do = 8421504, Lo = /* @__PURE__ */ new st(), Ur = /* @__PURE__ */ new j(), Na = /* @__PURE__ */ new j(), Ii = [], ym = /* @__PURE__ */ new j(), Oa = "+x+y";
function Fo(a) {
  return Array.isArray(a) ? a[0] : a;
}
let vl = () => {
  const a = new Nt(
    new zn(1, 1),
    is
  );
  return vl = () => a, a;
}, _l = () => {
  const a = new Nt(
    new zn(1, 1, 32, 1),
    is
  );
  return _l = () => a, a;
};
const Mm = { type: "syncstart" }, Em = { type: "synccomplete" }, xl = [
  "font",
  "fontSize",
  "fontStyle",
  "fontWeight",
  "lang",
  "letterSpacing",
  "lineHeight",
  "maxWidth",
  "overflowWrap",
  "text",
  "direction",
  "textAlign",
  "textIndent",
  "whiteSpace",
  "anchorX",
  "anchorY",
  "colorRanges",
  "sdfGlyphSize"
], Tm = xl.concat(
  "material",
  "color",
  "depthOffset",
  "clipRect",
  "curveRadius",
  "orientation",
  "glyphGeometryDetail"
);
class Sl extends Nt {
  constructor() {
    const e = new mm();
    super(e, null), this.text = "", this.anchorX = 0, this.anchorY = 0, this.curveRadius = 0, this.direction = "auto", this.font = null, this.unicodeFontsURL = null, this.fontSize = 0.1, this.fontWeight = "normal", this.fontStyle = "normal", this.lang = null, this.letterSpacing = 0, this.lineHeight = "normal", this.maxWidth = 1 / 0, this.overflowWrap = "normal", this.textAlign = "left", this.textIndent = 0, this.whiteSpace = "normal", this.material = null, this.color = null, this.colorRanges = null, this.outlineWidth = 0, this.outlineColor = 0, this.outlineOpacity = 1, this.outlineBlur = 0, this.outlineOffsetX = 0, this.outlineOffsetY = 0, this.strokeWidth = 0, this.strokeColor = Do, this.strokeOpacity = 1, this.fillOpacity = 1, this.depthOffset = 0, this.clipRect = null, this.orientation = Oa, this.glyphGeometryDetail = 1, this.sdfGlyphSize = null, this.gpuAccelerateSDF = !0, this.debugSDF = !1;
  }
  /**
   * Updates the text rendering according to the current text-related configuration properties.
   * This is an async process, so you can pass in a callback function to be executed when it
   * finishes.
   * @param {function} [callback]
   */
  sync(e) {
    this._needsSync && (this._needsSync = !1, this._isSyncing ? (this._queuedSyncs || (this._queuedSyncs = [])).push(e) : (this._isSyncing = !0, this.dispatchEvent(Mm), om({
      text: this.text,
      font: this.font,
      lang: this.lang,
      fontSize: this.fontSize || 0.1,
      fontWeight: this.fontWeight || "normal",
      fontStyle: this.fontStyle || "normal",
      letterSpacing: this.letterSpacing || 0,
      lineHeight: this.lineHeight || "normal",
      maxWidth: this.maxWidth,
      direction: this.direction || "auto",
      textAlign: this.textAlign,
      textIndent: this.textIndent,
      whiteSpace: this.whiteSpace,
      overflowWrap: this.overflowWrap,
      anchorX: this.anchorX,
      anchorY: this.anchorY,
      colorRanges: this.colorRanges,
      includeCaretPositions: !0,
      //TODO parameterize
      sdfGlyphSize: this.sdfGlyphSize,
      gpuAccelerateSDF: this.gpuAccelerateSDF,
      unicodeFontsURL: this.unicodeFontsURL
    }, (t) => {
      this._isSyncing = !1, this._textRenderInfo = t, this.geometry.updateGlyphs(
        t.glyphBounds,
        t.glyphAtlasIndices,
        t.blockBounds,
        t.chunkedBounds,
        t.glyphColors
      );
      const r = this._queuedSyncs;
      r && (this._queuedSyncs = null, this._needsSync = !0, this.sync(() => {
        r.forEach((n) => n && n());
      })), this.dispatchEvent(Em), e && e();
    })));
  }
  /**
   * Initiate a sync if needed - note it won't complete until next frame at the
   * earliest so if possible it's a good idea to call sync() manually as soon as
   * all the properties have been set.
   * @override
   */
  onBeforeRender(e, t, r, n, i, s) {
    this.sync(), i.isTroikaTextMaterial && this._prepareForRender(i);
  }
  /**
   * Shortcut to dispose the geometry specific to this instance.
   * Note: we don't also dispose the derived material here because if anything else is
   * sharing the same base material it will result in a pause next frame as the program
   * is recompiled. Instead users can dispose the base material manually, like normal,
   * and we'll also dispose the derived material at that time.
   */
  dispose() {
    this.geometry.dispose();
  }
  /**
   * @property {TroikaTextRenderInfo|null} textRenderInfo
   * @readonly
   * The current processed rendering data for this TextMesh, returned by the TextBuilder after
   * a `sync()` call. This will be `null` initially, and may be stale for a short period until
   * the asynchrous `sync()` process completes.
   */
  get textRenderInfo() {
    return this._textRenderInfo || null;
  }
  /**
   * Create the text derived material from the base material. Can be overridden to use a custom
   * derived material.
   */
  createDerivedMaterial(e) {
    return Sm(e);
  }
  // Handler for automatically wrapping the base material with our upgrades. We do the wrapping
  // lazily on _read_ rather than write to avoid unnecessary wrapping on transient values.
  get material() {
    let e = this._derivedMaterial;
    const t = this._baseMaterial || this._defaultMaterial || (this._defaultMaterial = is.clone());
    if ((!e || !e.isDerivedFrom(t)) && (e = this._derivedMaterial = this.createDerivedMaterial(t), t.addEventListener("dispose", function r() {
      t.removeEventListener("dispose", r), e.dispose();
    })), this.outlineWidth || this.outlineBlur || this.outlineOffsetX || this.outlineOffsetY) {
      let r = e._outlineMtl;
      return r || (r = e._outlineMtl = Object.create(e, {
        id: { value: e.id + 0.1 }
      }), r.isTextOutlineMaterial = !0, r.depthWrite = !1, r.map = null, e.addEventListener("dispose", function n() {
        e.removeEventListener("dispose", n), r.dispose();
      })), [
        r,
        e
      ];
    } else
      return e;
  }
  set material(e) {
    e && e.isTroikaTextMaterial ? (this._derivedMaterial = e, this._baseMaterial = e.baseMaterial) : this._baseMaterial = e;
  }
  get glyphGeometryDetail() {
    return this.geometry.detail;
  }
  set glyphGeometryDetail(e) {
    this.geometry.detail = e;
  }
  get curveRadius() {
    return this.geometry.curveRadius;
  }
  set curveRadius(e) {
    this.geometry.curveRadius = e;
  }
  // Create and update material for shadows upon request:
  get customDepthMaterial() {
    return Fo(this.material).getDepthMaterial();
  }
  get customDistanceMaterial() {
    return Fo(this.material).getDistanceMaterial();
  }
  _prepareForRender(e) {
    const t = e.isTextOutlineMaterial, r = e.uniforms, n = this.textRenderInfo;
    if (n) {
      const { sdfTexture: o, blockBounds: l } = n;
      r.uTroikaSDFTexture.value = o, r.uTroikaSDFTextureSize.value.set(o.image.width, o.image.height), r.uTroikaSDFGlyphSize.value = n.sdfGlyphSize, r.uTroikaSDFExponent.value = n.sdfExponent, r.uTroikaTotalBounds.value.fromArray(l), r.uTroikaUseGlyphColors.value = !t && !!n.glyphColors;
      let c = 0, u = 0, f = 0, h, d, g, v = 0, m = 0;
      if (t) {
        let { outlineWidth: T, outlineOffsetX: x, outlineOffsetY: _, outlineBlur: D, outlineOpacity: C } = this;
        c = this._parsePercent(T) || 0, u = Math.max(0, this._parsePercent(D) || 0), h = C, v = this._parsePercent(x) || 0, m = this._parsePercent(_) || 0;
      } else
        f = Math.max(0, this._parsePercent(this.strokeWidth) || 0), f && (g = this.strokeColor, r.uTroikaStrokeColor.value.set(g ?? Do), d = this.strokeOpacity, d == null && (d = 1)), h = this.fillOpacity;
      r.uTroikaDistanceOffset.value = c, r.uTroikaPositionOffset.value.set(v, m), r.uTroikaBlurRadius.value = u, r.uTroikaStrokeWidth.value = f, r.uTroikaStrokeOpacity.value = d, r.uTroikaFillOpacity.value = h ?? 1, r.uTroikaCurveRadius.value = this.curveRadius || 0;
      let p = this.clipRect;
      if (p && Array.isArray(p) && p.length === 4)
        r.uTroikaClipRect.value.fromArray(p);
      else {
        const T = (this.fontSize || 0.1) * 100;
        r.uTroikaClipRect.value.set(
          l[0] - T,
          l[1] - T,
          l[2] + T,
          l[3] + T
        );
      }
      this.geometry.applyClipRect(r.uTroikaClipRect.value);
    }
    r.uTroikaSDFDebug.value = !!this.debugSDF, e.polygonOffset = !!this.depthOffset, e.polygonOffsetFactor = e.polygonOffsetUnits = this.depthOffset || 0;
    const i = t ? this.outlineColor || 0 : this.color;
    if (i == null)
      delete e.color;
    else {
      const o = e.hasOwnProperty("color") ? e.color : e.color = new Ke();
      (i !== o._input || typeof i == "object") && o.set(o._input = i);
    }
    let s = this.orientation || Oa;
    if (s !== e._orientation) {
      let o = r.uTroikaOrient.value;
      s = s.replace(/[^-+xyz]/g, "");
      let l = s !== Oa && s.match(/^([-+])([xyz])([-+])([xyz])$/);
      if (l) {
        let [, c, u, f, h] = l;
        Ur.set(0, 0, 0)[u] = c === "-" ? 1 : -1, Na.set(0, 0, 0)[h] = f === "-" ? -1 : 1, Lo.lookAt(ym, Ur.cross(Na), Na), o.setFromMatrix4(Lo);
      } else
        o.identity();
      e._orientation = s;
    }
  }
  _parsePercent(e) {
    if (typeof e == "string") {
      let t = e.match(/^(-?[\d.]+)%$/), r = t ? parseFloat(t[1]) : NaN;
      e = (isNaN(r) ? 0 : r / 100) * this.fontSize;
    }
    return e;
  }
  /**
   * Translate a point in local space to an x/y in the text plane.
   */
  localPositionToTextCoords(e, t = new Ce()) {
    t.copy(e);
    const r = this.curveRadius;
    return r && (t.x = Math.atan2(e.x, Math.abs(r) - Math.abs(e.z)) * Math.abs(r)), t;
  }
  /**
   * Translate a point in world space to an x/y in the text plane.
   */
  worldPositionToTextCoords(e, t = new Ce()) {
    return Ur.copy(e), this.localPositionToTextCoords(this.worldToLocal(Ur), t);
  }
  /**
   * @override Custom raycasting to test against the whole text block's max rectangular bounds
   * TODO is there any reason to make this more granular, like within individual line or glyph rects?
   */
  raycast(e, t) {
    const { textRenderInfo: r, curveRadius: n } = this;
    if (r) {
      const i = r.blockBounds, s = n ? _l() : vl(), o = s.geometry, { position: l, uv: c } = o.attributes;
      for (let u = 0; u < c.count; u++) {
        let f = i[0] + c.getX(u) * (i[2] - i[0]);
        const h = i[1] + c.getY(u) * (i[3] - i[1]);
        let d = 0;
        n && (d = n - Math.cos(f / n) * n, f = Math.sin(f / n) * n), l.setXYZ(u, f, h, d);
      }
      o.boundingSphere = this.geometry.boundingSphere, o.boundingBox = this.geometry.boundingBox, s.matrixWorld = this.matrixWorld, s.material.side = this.material.side, Ii.length = 0, s.raycast(e, Ii);
      for (let u = 0; u < Ii.length; u++)
        Ii[u].object = this, t.push(Ii[u]);
    }
  }
  copy(e) {
    const t = this.geometry;
    return super.copy(e), this.geometry = t, Tm.forEach((r) => {
      this[r] = e[r];
    }), this;
  }
  clone() {
    return new this.constructor().copy(this);
  }
}
xl.forEach((a) => {
  const e = "_private_" + a;
  Object.defineProperty(Sl.prototype, a, {
    get() {
      return this[e];
    },
    set(t) {
      t !== this[e] && (this[e] = t, this._needsSync = !0);
    }
  });
});
new An();
new Ke();
const Wr = {};
Object.defineProperty(Wr, "__esModule", { value: !0 });
Wr.parseDxfMTextContent = void 0;
var bm = {
  d: "°",
  c: "⌀",
  p: "±"
}, yl = function(a, e) {
  var t, r, n, i;
  a = a.replace(/%%(.)/g, function(L, B) {
    return bm[B] || B;
  });
  for (var s = e == null ? void 0 : e.encoding, o = s instanceof TextDecoder ? s : void 0, l = "", c, u = [], f = function(L) {
    l && (u.push(l), l = ""), u.push(L);
  }, h = 0; h < a.length; h++)
    switch (c = a[h]) {
      default:
        l += c;
        break;
      case "\\": {
        switch (c = a[++h]) {
          default:
            l += c;
            break;
          case "P":
            l += `
`;
            break;
          case "f":
          case "F": {
            for (var d = ""; c = a[++h]; ) {
              if (c === ";") {
                f({ f: d });
                break;
              }
              if (c === "|") {
                for (var g = { f: d }, v = a.indexOf(";", ++h), m = 0, p = a.slice(h, v).split("|"); m < p.length; m++) {
                  var T = p[m];
                  g[T[0]] = +T.slice(1);
                }
                h = v, f(g);
                break;
              }
              d += c === "\\" ? a[++h] : c;
            }
            break;
          }
          case "S": {
            for (var x = "", _ = void 0, D = ""; c = a[++h]; ) {
              if (c === ";") {
                _ && f({ S: [x, _, D] });
                break;
              }
              c === "\\" ? _ ? D += a[++h] : x += a[++h] : _ ? D += c : c === "^" || c === "/" || c === "#" ? _ = c : x += c;
            }
            break;
          }
          case "H":
          case "W":
            var C = ++h, A = a.slice(C, h = a.indexOf(";", h)).match(/^(\d*(?:\.\d+)?)(\D*)$/), R = A[1], E = A[2];
            f((t = {}, t[c] = [+R, E], t));
            break;
          case "Q":
          case "A":
          case "C":
          case "T": {
            var S = ++h;
            f((r = {}, r[c] = +a.slice(S, h = a.indexOf(";", h)), r));
            break;
          }
          case "L":
          case "O":
          case "K":
            f((n = {}, n[c] = 1, n));
            break;
          case "l":
          case "o":
          case "k":
            f((i = {}, i[c.toUpperCase()] = 0, i));
            break;
          case "U":
          case "u":
            a[h + 1] === "+" ? (l += String.fromCodePoint(parseInt(a.substr(h + 2, 4), 16)), h += 5) : l += c;
            break;
          case "M":
          case "m":
            s ? a[h + 1] === "+" && a[h + 2] === "1" ? (l += (o = o || new TextDecoder(s)).decode(
              new Uint8Array([
                parseInt(a.substr(h + 3, 2), 16),
                parseInt(a.substr(h + 5, 2), 16)
              ])
            ), h += 6) : l += c : l += "\\" + c;
            break;
        }
        break;
      }
      case "{": {
        for (var F = 1, C = h; c = a[++h]; )
          if (c === "{")
            F++;
          else if (c === "}") {
            if (--F === 0) {
              f((0, Wr.parseDxfMTextContent)(a.slice(C + 1, h)));
              break;
            }
          } else c === "\\" && h++;
        break;
      }
    }
  return l && u.push(l), u;
};
Wr.parseDxfMTextContent = yl;
var ui = { Math: {} };
ui.Math.angle2 = function(a, e) {
  var t = new Ce(a.x, a.y), r = new Ce(e.x, e.y);
  return r.sub(t), r.normalize(), r.y < 0 ? -Math.acos(r.x) : Math.acos(r.x);
};
ui.Math.polar = function(a, e, t) {
  var r = {};
  return r.x = a.x + e * Math.cos(t), r.y = a.y + e * Math.sin(t), r;
};
function Am(a, e, t, r) {
  var n, i, s, o, l, c, u, f, h;
  o = a ? new Ce(a.x, a.y) : new Ce(0, 0), l = e ? new Ce(e.x, e.y) : new Ce(1, 0), t = t || 1, c = 4 * Math.atan(t), u = o.distanceTo(l) / 2 / Math.sin(c / 2), s = ui.Math.polar(
    a,
    u,
    ui.Math.angle2(o, l) + (Math.PI / 2 - c / 2)
  ), r = r || Math.max(Math.abs(Math.ceil(c / (Math.PI / 18))), 6), f = ui.Math.angle2(s, o), h = c / r;
  var d = [];
  for (d.push(new j(o.x, o.y, 0)), i = 1; i <= r - 1; i++)
    n = ui.Math.polar(s, Math.abs(u), f + h * i), d.push(new j(n.x, n.y, 0));
  return d;
}
function wm(a, e, t, r, n) {
  Y(a);
  var i = new Nd(), s, o, l, c = {
    min: { x: 0, y: 0, z: 0 },
    max: { x: 0, y: 0, z: 0 }
  };
  for (s = 0; s < a.entities.length; s++) {
    if (o = a.entities[s], l = C(o, a), l) {
      var u = new An().setFromObject(l);
      isFinite(u.min.x) && c.min.x > u.min.x && (c.min.x = u.min.x), isFinite(u.min.y) && c.min.y > u.min.y && (c.min.y = u.min.y), isFinite(u.min.z) && c.min.z > u.min.z && (c.min.z = u.min.z), isFinite(u.max.x) && c.max.x < u.max.x && (c.max.x = u.max.x), isFinite(u.max.y) && c.max.y < u.max.y && (c.max.y = u.max.y), isFinite(u.max.z) && c.max.z < u.max.z && (c.max.z = u.max.z), i.add(l);
    }
    l = null;
  }
  t = t || e.clientWidth, r = r || e.clientHeight;
  var f = t / r, h = { x: c.max.x, y: c.max.y }, d = { x: c.min.x, y: c.min.y }, g = h.x - d.x, v = h.y - d.y, m = m || {
    x: g / 2 + d.x,
    y: v / 2 + d.y
  }, p = Math.abs(g / v);
  f > p ? g = v * f : v = g / f;
  var T = {
    bottom: -v / 2,
    left: -g / 2,
    top: v / 2,
    right: g / 2,
    center: {
      x: m.x,
      y: m.y
    }
  }, x = new Yo(
    T.left,
    T.right,
    T.top,
    T.bottom,
    1,
    19
  );
  x.position.z = 10, x.position.x = T.center.x, x.position.y = T.center.y;
  var _ = this.renderer = new Id();
  _.setSize(t, r), _.setClearColor(268435455, 0), e.appendChild(_.domElement), e.style.display = "block";
  var D = new ul(x, e);
  D.target.x = x.position.x, D.target.y = x.position.y, D.target.z = 0, D.zoomSpeed = 1, this.render = function() {
    _.render(i, x);
  }, D.addEventListener("change", this.render), this.render(), D.update(), this.resize = function(b, U) {
    var G = _.domElement.width, I = _.domElement.height, V = b / G, re = U / I;
    x.top = re * x.top, x.bottom = re * x.bottom, x.left = V * x.left, x.right = V * x.right, _.setSize(b, U), _.setClearColor(268435455, 1), this.render();
  };
  function C(b, U) {
    var G;
    if (b.type === "CIRCLE" || b.type === "ARC")
      G = k(b, U);
    else if (b.type === "LWPOLYLINE" || b.type === "LINE" || b.type === "POLYLINE")
      G = B(b, U);
    else if (b.type === "TEXT")
      G = ne(b, U);
    else if (b.type === "SOLID")
      G = z(b, U);
    else if (b.type === "POINT")
      G = q(b, U);
    else if (b.type === "INSERT")
      G = Z(b, U);
    else if (b.type === "SPLINE")
      G = F(b, U);
    else if (b.type === "MTEXT")
      G = R(b, U);
    else if (b.type === "ELLIPSE")
      G = A(b, U);
    else if (b.type === "DIMENSION") {
      var I = b.dimensionType & 7;
      I === 0 ? G = K(b, U) : console.log("Unsupported Dimension type: " + I);
    } else
      console.log("Unsupported Entity Type: " + b.type);
    return G;
  }
  function A(b, U) {
    var G = N(b, U), I = Math.sqrt(
      Math.pow(b.majorAxisEndPoint.x, 2) + Math.pow(b.majorAxisEndPoint.y, 2)
    ), V = I * b.axisRatio, re = Math.atan2(b.majorAxisEndPoint.y, b.majorAxisEndPoint.x), he = new zr(
      b.center.x,
      b.center.y,
      I,
      V,
      b.startAngle,
      b.endAngle,
      !1,
      // Always counterclockwise
      re
    ), fe = he.getPoints(50), W = new St().setFromPoints(fe), ce = new li({ linewidth: 1, color: G }), P = new Er(W, ce);
    return P;
  }
  function R(b, U) {
    var G = N(b, U);
    if (!n)
      return console.log("font parameter not set. Ignoring text entity.");
    var I = yl(b.text), V = E(I, b), re = S(V.text, V.style, b, G), he = new gt();
    return he.add(re), he;
  }
  function E(b, U, G) {
    let I = {
      horizontalAlignment: "left",
      textHeight: U.height
    };
    var V = [];
    for (let he of b)
      if (typeof he == "string")
        he.startsWith("pxq") && he.endsWith(";") ? he.indexOf("c") !== -1 ? I.horizontalAlignment = "center" : he.indexOf("l") !== -1 ? I.horizontalAlignment = "left" : he.indexOf("r") !== -1 ? I.horizontalAlignment = "right" : he.indexOf("j") !== -1 && (I.horizontalAlignment = "justify") : V.push(he);
      else if (Array.isArray(he)) {
        var re = E(he, U);
        V.push(re.text);
      } else typeof he == "object" && he.S && he.S.length === 3 && V.push(he.S[0] + "/" + he.S[2]);
    return {
      text: V.join(),
      style: I
    };
  }
  function S(b, U, G, I) {
    if (!b) return null;
    let V = new Sl();
    if (V.text = b.replaceAll("\\P", `
`).replaceAll("\\X", `
`), V.fontSize = U.textHeight, V.maxWidth = G.width || 1 / 0, V.position.x = G.position.x, V.position.y = G.position.y, V.position.z = G.position.z, V.textAlign = U.horizontalAlignment, V.color = I, G.rotation && (V.rotation.z = G.rotation * Math.PI / 180), G.directionVector) {
      var re = G.directionVector;
      V.rotation.z = new j(1, 0, 0).angleTo(new j(re.x, re.y, re.z));
    }
    switch (G.attachmentPoint) {
      case 1:
        V.anchorX = "left", V.anchorY = "top";
        break;
      case 2:
        V.anchorX = "center", V.anchorY = "top";
        break;
      case 3:
        V.anchorX = "right", V.anchorY = "top";
        break;
      case 4:
        V.anchorX = "left", V.anchorY = "middle";
        break;
      case 5:
        V.anchorX = "center", V.anchorY = "middle";
        break;
      case 6:
        V.anchorX = "right", V.anchorY = "middle";
        break;
      case 7:
        V.anchorX = "left", V.anchorY = "bottom";
        break;
      case 8:
        V.anchorX = "center", V.anchorY = "bottom";
        break;
      case 9:
        V.anchorX = "right", V.anchorY = "bottom";
        break;
      default:
        return;
    }
    return V.sync(() => {
      if (V.textAlign !== "left") {
        V.geometry.computeBoundingBox();
        var he = V.geometry.boundingBox.max.x - V.geometry.boundingBox.min.x;
        V.textAlign === "center" && (V.position.x += (G.width - he) / 2), V.textAlign === "right" && (V.position.x += G.width - he);
      }
    }), V;
  }
  function F(b, U) {
    var G = N(b, U), I = L(
      b.controlPoints,
      b.degreeOfSplineCurve,
      b.knotValues,
      100
    ), V = new St().setFromPoints(I), re = new li({ linewidth: 1, color: G }), he = new Er(V, re);
    return he;
  }
  function L(b, U, G, I, V) {
    const re = [], he = b.map(function(ce) {
      return [ce.x, ce.y];
    }), fe = [G[U]], W = [G[U], G[G.length - 1 - U]];
    for (let ce = U + 1; ce < G.length - U; ++ce)
      fe[fe.length - 1] !== G[ce] && fe.push(G[ce]);
    I = I || 25;
    for (let ce = 1; ce < fe.length; ++ce) {
      const P = fe[ce - 1], pe = fe[ce];
      for (let ae = 0; ae <= I; ++ae) {
        let te = (ae / I * (pe - P) + P - W[0]) / (W[1] - W[0]);
        te = Math.max(te, 0), te = Math.min(te, 1);
        const Te = Rp(te, U, he, G, V);
        re.push(new Ce(Te[0], Te[1]));
      }
    }
    return re;
  }
  function B(b, U) {
    let G = [], I = N(b, U);
    var V, re, he, fe, W, ce, P, pe;
    if (!b.vertices) return console.log("entity missing vertices.");
    for (P = 0; P < b.vertices.length; P++)
      if (b.vertices[P].bulge) {
        ce = b.vertices[P].bulge, fe = b.vertices[P], W = P + 1 < b.vertices.length ? b.vertices[P + 1] : G[0];
        let ve = Am(fe, W, ce);
        G.push.apply(G, ve);
      } else
        he = b.vertices[P], G.push(new j(he.x, he.y, 0));
    b.shape && G.push(G[0]), b.lineType && (re = U.tables.lineType.lineTypes[b.lineType]), re && re.pattern && re.pattern.length !== 0 ? V = new gp({ color: I, gapSize: 4, dashSize: 4 }) : V = new li({ linewidth: 1, color: I });
    var ae = new St().setFromPoints(G);
    return pe = new Er(ae, V), pe;
  }
  function k(b, U) {
    var G, I;
    b.type === "CIRCLE" ? (G = b.startAngle || 0, I = G + 2 * Math.PI) : (G = b.startAngle, I = b.endAngle);
    var V = new nl(0, 0, b.radius, G, I), re = V.getPoints(32), he = new St().setFromPoints(re), fe = new li({ color: N(b, U) }), W = new Er(he, fe);
    return W.position.x = b.center.x, W.position.y = b.center.y, W.position.z = b.center.z, W;
  }
  function O(b, U, G, I) {
    var V = new j(), re = new j();
    V.subVectors(G, U), re.subVectors(I, U), V.cross(re);
    var he = new j(U.x, U.y, U.z), fe = new j(G.x, G.y, G.z), W = new j(I.x, I.y, I.z);
    V.z < 0 ? b.push(W, fe, he) : b.push(he, fe, W);
  }
  function z(b, U) {
    var G, I, V = new St(), re = b.points;
    return I = [], O(I, re[0], re[1], re[2]), O(I, re[1], re[2], re[3]), G = new Vi({ color: N(b, U) }), V.setFromPoints(I), new Nt(V, G);
  }
  function ne(b, U) {
    var G, I, V;
    if (!n)
      return console.warn(
        "Text is not supported without a Three.js font loaded with THREE.FontLoader! Load a font of your choice and pass this into the constructor. See the sample for this repository or Three.js examples at http://threejs.org/examples/?q=text#webgl_geometry_text for more details."
      );
    if (G = new Ep(b.text.replaceAll("%%u", ""), {
      font: n,
      depth: 0,
      size: b.textHeight || 12
    }), b.rotation) {
      var re = b.rotation * Math.PI / 180;
      G.rotateZ(re);
    }
    return I = new Vi({
      color: N(b, U),
      side: 2
      // 正交相机 需要双面
    }), V = new Nt(G, I), V.position.x = b.startPoint.x, V.position.y = b.startPoint.y, V.position.z = b.startPoint.z, V;
  }
  function q(b, U) {
    var G, I, V;
    G = new St(), G.setAttribute(
      "position",
      new tn([b.position.x, b.position.y, b.position.z], 3)
    );
    var re = N(b, U);
    I = new tl({ size: 0.1, color: new Ke(re) }), V = new Bd(G, I), i.add(V);
  }
  function K(b, U) {
    var G = U.blocks[b.block];
    if (!G || !G.entities) return null;
    for (var I = new gt(), V = 0; V < G.entities.length; V++) {
      var re = C(G.entities[V], U);
      re && I.add(re);
    }
    return I;
  }
  function Z(b, U) {
    var G = U.blocks[b.name];
    if (!G.entities) return null;
    var I = new gt();
    b.xScale && (I.scale.x = b.xScale), b.yScale && (I.scale.y = b.yScale), b.rotation && (I.rotation.z = b.rotation * Math.PI / 180), b.position && (I.position.x = b.position.x, I.position.y = b.position.y, I.position.z = b.position.z);
    for (var V = 0; V < G.entities.length; V++) {
      var re = C(G.entities[V], U);
      re && I.add(re);
    }
    return I;
  }
  function N(b, U) {
    var G = 0;
    return b.color ? G = b.color : U.tables && U.tables.layer && U.tables.layer.layers[b.layer] && (G = U.tables.layer.layers[b.layer].color), (G == null || G === 16777215) && (G = 0), G;
  }
  function Y(b) {
    var U, G;
    if (!(!b.tables || !b.tables.lineType)) {
      var I = b.tables.lineType.lineTypes;
      for (G in I)
        U = I[G], U.pattern && (U.material = ie(U.pattern));
    }
  }
  function ie(b) {
    var U, G = {}, I = 0;
    for (U = 0; U < b.length; U++)
      I += Math.abs(b[U]);
    return G.uniforms = Qa.merge([
      Le.common,
      Le.fog,
      {
        pattern: { type: "fv1", value: b },
        patternLength: { type: "f", value: I }
      }
    ]), G.vertexShader = [
      "attribute float lineDistance;",
      "varying float vLineDistance;",
      Xe.color_pars_vertex,
      "void main() {",
      Xe.color_vertex,
      "vLineDistance = lineDistance;",
      "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
      "}"
    ].join(`
`), G.fragmentShader = [
      "uniform vec3 diffuse;",
      "uniform float opacity;",
      "uniform float pattern[" + b.length + "];",
      "uniform float patternLength;",
      "varying float vLineDistance;",
      Xe.color_pars_fragment,
      Xe.fog_pars_fragment,
      "void main() {",
      "float pos = mod(vLineDistance, patternLength);",
      "for ( int i = 0; i < " + b.length + "; i++ ) {",
      "pos = pos - abs(pattern[i]);",
      "if( pos < 0.0 ) {",
      "if( pattern[i] > 0.0 ) {",
      "gl_FragColor = vec4(1.0, 0.0, 0.0, opacity );",
      "break;",
      "}",
      "discard;",
      "}",
      "}",
      Xe.color_fragment,
      Xe.fog_fragment,
      "}"
    ].join(`
`), G;
  }
}
let Ba = null;
const Cm = new Tp();
async function Rm(a, e, t, r, n) {
  return !Ba && n && (Ba = await new Promise((i) => {
    Cm.load(n, (s) => i(s));
  })), new wm(a, e, t, r, Ba);
}
window.threeDxfViewer = Rm;
export {
  wm as Viewer,
  Rm as default
};
